Submission #4032523


Source Code Expand

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int N;
  cin >> N;
  vector<P> p;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    p.pb(P(tmp, i));
  }

  sort(ALL(p));

  int sum = 0, max = 0, cont = 1;
  for (int i = 0; i + 1 < N; i++) {
    if (p[i].second > p[i + 1].second) {
      sum += cont;
      chmax(max, cont);
      cont = 1;
    } else {
      cont++;
    }
  }
  if (cont != 0) {
    sum += cont;
    chmax(max, cont);
  }

  cout << sum - max << endl;
  return 0;
}

Submission Info

Submission Time
Task B - Backfront
User null_null
Language C++14 (GCC 5.4.1)
Score 500
Code Size 2420 Byte
Status AC
Exec Time 81 ms
Memory 6512 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 28
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 81 ms 6512 KB
02.txt AC 77 ms 5744 KB
03.txt AC 81 ms 4976 KB
04.txt AC 77 ms 5872 KB
05.txt AC 77 ms 4720 KB
06.txt AC 77 ms 5232 KB
07.txt AC 66 ms 6128 KB
08.txt AC 66 ms 6128 KB
09.txt AC 66 ms 5872 KB
10.txt AC 65 ms 4464 KB
11.txt AC 75 ms 4848 KB
12.txt AC 73 ms 4592 KB
13.txt AC 75 ms 5744 KB
14.txt AC 76 ms 6000 KB
15.txt AC 76 ms 6000 KB
16.txt AC 76 ms 6384 KB
17.txt AC 76 ms 5104 KB
18.txt AC 77 ms 4464 KB
19.txt AC 66 ms 5488 KB
20.txt AC 67 ms 6384 KB
21.txt AC 74 ms 4976 KB
22.txt AC 74 ms 5104 KB
23.txt AC 1 ms 256 KB
24.txt AC 1 ms 256 KB
25.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 1 ms 256 KB