#include <bits/stdc++.h>
using namespace std;
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));
for(int k=0; k<n; k++){
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-1; 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;
cur-=r-n;
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];
}
pair<int,int> ans={1e8,-1};
for(int i=0; i<2*n; i++){
int x=calc();
if(x<=ans.first) ans={x,i};
if(i<2*n-1){
at++;
swap(arr[i],arr[i+1]);
}
}
cout << ans.second/2+1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
5 ms |
348 KB |
Output isn't correct |
4 |
Execution timed out |
2054 ms |
348 KB |
Time limit exceeded |
5 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
6 |
Incorrect |
35 ms |
348 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Incorrect |
38 ms |
348 KB |
Output isn't correct |
3 |
Execution timed out |
2069 ms |
348 KB |
Time limit exceeded |
4 |
Execution timed out |
2073 ms |
604 KB |
Time limit exceeded |
5 |
Runtime error |
2 ms |
860 KB |
Execution killed with signal 11 |
6 |
Incorrect |
47 ms |
348 KB |
Output isn't correct |
7 |
Execution timed out |
2086 ms |
344 KB |
Time limit exceeded |
8 |
Runtime error |
1 ms |
664 KB |
Execution killed with signal 11 |
9 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
10 |
Execution timed out |
2067 ms |
348 KB |
Time limit exceeded |
11 |
Runtime error |
2 ms |
856 KB |
Execution killed with signal 11 |
12 |
Execution timed out |
2069 ms |
348 KB |
Time limit exceeded |
13 |
Runtime error |
2 ms |
856 KB |
Execution killed with signal 11 |
14 |
Execution timed out |
2094 ms |
348 KB |
Time limit exceeded |
15 |
Runtime error |
1 ms |
844 KB |
Execution killed with signal 11 |
16 |
Incorrect |
41 ms |
348 KB |
Output isn't correct |
17 |
Execution timed out |
2065 ms |
348 KB |
Time limit exceeded |
18 |
Execution timed out |
2043 ms |
348 KB |
Time limit exceeded |
19 |
Execution timed out |
2033 ms |
344 KB |
Time limit exceeded |
20 |
Execution timed out |
2045 ms |
344 KB |
Time limit exceeded |
21 |
Runtime error |
1 ms |
856 KB |
Execution killed with signal 11 |
22 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
23 |
Runtime error |
1 ms |
928 KB |
Execution killed with signal 11 |
24 |
Incorrect |
39 ms |
600 KB |
Output isn't correct |
25 |
Execution timed out |
2065 ms |
344 KB |
Time limit exceeded |
26 |
Execution timed out |
2052 ms |
348 KB |
Time limit exceeded |
27 |
Runtime error |
2 ms |
856 KB |
Execution killed with signal 11 |
28 |
Runtime error |
2 ms |
860 KB |
Execution killed with signal 11 |
29 |
Execution timed out |
2097 ms |
348 KB |
Time limit exceeded |
30 |
Execution timed out |
2035 ms |
344 KB |
Time limit exceeded |
31 |
Runtime error |
1 ms |
856 KB |
Execution killed with signal 11 |
32 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
33 |
Incorrect |
40 ms |
348 KB |
Output isn't correct |
34 |
Incorrect |
41 ms |
344 KB |
Output isn't correct |
35 |
Execution timed out |
2029 ms |
344 KB |
Time limit exceeded |
36 |
Execution timed out |
2004 ms |
344 KB |
Time limit exceeded |
37 |
Execution timed out |
2033 ms |
604 KB |
Time limit exceeded |
38 |
Runtime error |
2 ms |
860 KB |
Execution killed with signal 11 |
39 |
Incorrect |
36 ms |
348 KB |
Output isn't correct |
40 |
Execution timed out |
2067 ms |
348 KB |
Time limit exceeded |
41 |
Execution timed out |
2041 ms |
344 KB |
Time limit exceeded |
42 |
Execution timed out |
2060 ms |
348 KB |
Time limit exceeded |
43 |
Execution timed out |
2057 ms |
348 KB |
Time limit exceeded |
44 |
Execution timed out |
2050 ms |
600 KB |
Time limit exceeded |
45 |
Runtime error |
2 ms |
856 KB |
Execution killed with signal 11 |
46 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
47 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |