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;
#define int long long
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, r, x;
cin >> n >> r >> x;
r %= (2*n);
int b[2*n-1];
for(int i = 0; i < 2*n-1; i++) cin >> b[i];
int a[2][2*n];
bool flag = 0;
int mn = n-1, ans = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < 2*n; j++) a[0][j] = 0;
a[0][2*i] = x;
int idx = 0;
for(int j = 0; j < 2*n; j++) if(!a[0][j]) {
a[0][j] = b[idx++];
}
flag = 0;
for(int j = 0; j < 2*n+r; j++) {
for(int k = 1; k < n; k++) {
a[flag^1][2*(k-1)] = min(a[flag][2*k], a[flag][2*k+1]);
a[flag^1][2*k+1] = max(a[flag][2*k], a[flag][2*k+1]);
}
a[flag^1][2*n-2] = max(a[flag][0], a[flag][1]);
a[flag^1][1] = min(a[flag][0], a[flag][1]);
flag ^= 1;
}
for(int j = 0; j < 2*n; j++) if(a[flag][j] == x) {
if(j/2 < mn) {
mn = j/2;
ans = i;
} else if(j/2 == mn) {
ans = max(ans, i);
}
}
}
cout << ans+1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |