This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
int main()
{
int n, r; cin >> n >> r;
int me; cin >> me;
vector<int> nv(2 * n - 1);
for (auto &i : nv) {
cin >> i;
}
nv.push_back(me);
int mnp = -1;
int mns = INT_MAX;
for (int i = 2 * n - 1; i > 0; i--) {
int mn = 0, mx = INT_MAX;
vector<int> v = nv;
while(mn < mx){
mn = INT_MAX;
mx = 0;
for (int j = 1; j < n; j++) {
mn = min(mn, max(v[2 * j], v[2 * j + 1]));
mx = max(mx, min(v[2 * j], v[2 * j + 1]));
}
if(v[0] != 1) mn = 0;
if(mn > mx) break;
vector<int> tv(2 * n);
if(v[0] > v[1]) swap(v[0], v[1]);
tv[0] = v[0];
tv[2 * n - 1] = v[1];
for (int j = 1; j < n; j++) {
int& s = v[2 * j], &b = v[2 * j + 1];
if(s < b) swap(s, b);
tv[2 * j] = s;
tv[2 * j - 1] = b;
}
v = tv;
}
for (int j = 0; j < 2 * n; j++) {
if(v[j] == me){
if(j / 2 < mns){
mns = j / 2;
mnp = i / 2 + 1;
}
break;
}
}
swap(nv[i], nv[i - 1]);
}
cout << mnp << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |