This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) begin(x), end(x)
const int maxn = 2020;
int n, r, p = 0, a[maxn], cur[maxn], sp = 0;
array<int, 2> ans = {100000, -1};
void check() {
for(int i = 0; i < n; i++) cur[i] = a[i];
//for(int i = 0; i < n; i++) cout << cur[i] << " "; cout << endl;
for(int it = 0; it < r; it++) {
for(int i = 1; i < n; i += 2)
if(cur[i] < cur[i-1]) swap(cur[i], cur[i-1]);
for(int i = 2; i < n; i++) swap(cur[i], cur[i-1]);
}
int pos = 0;
while(cur[pos]) pos++;
ans = min(ans, {pos, -sp});
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> r;
n *= 2;
r = r%(2*n);
r += 2*n;
cin >> p;
for(int i = 1; i < n; i++) {
cin >> a[i];
}
for(int i = 1; i < n; i++) {
a[i] = a[i] < p ? -1 : 1;
}
check();
for(int i = 1; i < n; i++) {
swap(a[i], a[i-1]);
sp++;
check();
}
cout << 1 + ((-ans[1])/2) << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |