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 = 404;
int n, r, p = 0, a[maxn], sp = 0;
char cur[maxn];
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++) {
#pragma GCC ivdep
for(int i = 1; i < n; i += 2) if(cur[i] < cur[i-1]) {
cur[i] ^= cur[i-1];
cur[i-1] ^= cur[i];
cur[i] ^= cur[i-1];
}
int FF = cur[1];
#pragma GCC ivdep
for(int i = 1; i+1 < n; i++) cur[i] = cur[i+1];
cur[n-1] = FF;
}
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... |