#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
int n;
long long r;
int arr[10005],brr[10005],at;
int calc(){
if(arr[at]==1) return 1;
for(int i=0; i<2*n; i++) brr[i]=arr[i];
int ex[n];
memset(ex,0,sizeof(ex));
int rnd=min(n,400);
for(int k=0; k<rnd; k++){
for(int j=0; j<n; j++) ex[j]=0;
if(brr[1]>brr[0]) ex[0]=1;
for(int j=1; j<n; j++){
if(brr[j<<1|1]<brr[j<<1]) ex[j]=1;
}
swap(brr[ex[0]],brr[(n-1)<<1|ex[n-1]]);
for(int i=0; i<n-2; i++){
swap(brr[i<<1|ex[i]],brr[(i+1)<<1|ex[i+1]]);
}
}
int cur=0;
for(int i=0; i<2*n; i++){
if(arr[at]==brr[i]) cur=i/2;
}
if(arr[at]>n) return cur+1;
cur-=r-rnd;
cur%=n;
if(cur<0) cur+=n;
return cur+1;
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> r;
for(int i=0; i<2*n; i++){
cin >> arr[i];
}
for(int i=0; i<2*n-1; i++) swap(arr[i],arr[i+1]);
at=2*n-1;
pair<int,int> ans={1e8,-1};
for(int i=2*n-1; i>=max(0,2*n-2000); i-=4){
int x=calc();
//cout << i << ' ' << x << '\n';
if(x<ans.first) ans={x,i};
if(i){
at--;
swap(arr[i],arr[i-1]);
at--;
swap(arr[i-1],arr[i-2]);
at--;
swap(arr[i-2],arr[i-3]);
at--;
swap(arr[i-3],arr[i-4]);
}
}
cout << ans.second/2+1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
784 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Correct |
6 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
6 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
565 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
1499 ms |
344 KB |
Output isn't correct |
5 |
Runtime error |
1 ms |
856 KB |
Execution killed with signal 11 |
6 |
Correct |
8 ms |
348 KB |
Output is correct |
7 |
Incorrect |
266 ms |
456 KB |
Output isn't correct |
8 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
9 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
10 |
Correct |
455 ms |
348 KB |
Output is correct |
11 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
12 |
Incorrect |
1131 ms |
348 KB |
Output isn't correct |
13 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
14 |
Correct |
1945 ms |
524 KB |
Output is correct |
15 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
16 |
Correct |
7 ms |
348 KB |
Output is correct |
17 |
Correct |
515 ms |
460 KB |
Output is correct |
18 |
Incorrect |
817 ms |
344 KB |
Output isn't correct |
19 |
Incorrect |
1566 ms |
348 KB |
Output isn't correct |
20 |
Incorrect |
1905 ms |
528 KB |
Output isn't correct |
21 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
22 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
23 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
24 |
Correct |
6 ms |
348 KB |
Output is correct |
25 |
Incorrect |
365 ms |
460 KB |
Output isn't correct |
26 |
Incorrect |
1843 ms |
344 KB |
Output isn't correct |
27 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
28 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
29 |
Incorrect |
609 ms |
348 KB |
Output isn't correct |
30 |
Incorrect |
1932 ms |
528 KB |
Output isn't correct |
31 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
32 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
33 |
Incorrect |
6 ms |
464 KB |
Output isn't correct |
34 |
Correct |
7 ms |
348 KB |
Output is correct |
35 |
Incorrect |
840 ms |
476 KB |
Output isn't correct |
36 |
Incorrect |
1047 ms |
488 KB |
Output isn't correct |
37 |
Incorrect |
1780 ms |
344 KB |
Output isn't correct |
38 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
39 |
Incorrect |
6 ms |
344 KB |
Output isn't correct |
40 |
Incorrect |
398 ms |
456 KB |
Output isn't correct |
41 |
Incorrect |
882 ms |
476 KB |
Output isn't correct |
42 |
Incorrect |
903 ms |
480 KB |
Output isn't correct |
43 |
Execution timed out |
2062 ms |
348 KB |
Time limit exceeded |
44 |
Incorrect |
1909 ms |
344 KB |
Output isn't correct |
45 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
46 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
47 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |