#include <bits/stdc++.h>
using namespace std;
const int N=5e5+10;
int n, r, s, a[N], b[N];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> r >> s;
// r=(r-n*2)%(n*2)+n*2;
for (int i=1; i<n*2; ++i) cin >> b[i];
pair<int, int> ans={n*2, n};
for (int i=1; i<=n; ++i){
for (int j=1; j<i*2; ++j) a[j]=b[j];
a[i*2]=s;
for (int j=i*2+1; j<=n*2; ++j) a[j]=b[j-1];
for (int _=1; _<=r; ++_){
for (int j=1; j<=n*2; j+=2) if (a[j]>a[j+1]) swap(a[j], a[j+1]);
swap(a[1], a[2]);
int tmp=a[1];
for (int j=3; j<=n*2; j+=2) a[j-2]=a[j];
a[n*2-1]=tmp;
}
int pos=0;
for (int j=1; j<=n*2; ++j) if (a[j]==s) pos=(j+1)/2;
ans=min(ans, {pos, -i});
}
cout << -ans.second << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Execution timed out |
2092 ms |
2396 KB |
Time limit exceeded |
3 |
Correct |
1247 ms |
2396 KB |
Output is correct |
4 |
Execution timed out |
2081 ms |
2396 KB |
Time limit exceeded |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Execution timed out |
2075 ms |
2396 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Execution timed out |
2097 ms |
2396 KB |
Time limit exceeded |
3 |
Execution timed out |
2057 ms |
2396 KB |
Time limit exceeded |
4 |
Execution timed out |
2072 ms |
2396 KB |
Time limit exceeded |
5 |
Execution timed out |
2054 ms |
3676 KB |
Time limit exceeded |
6 |
Execution timed out |
2074 ms |
2396 KB |
Time limit exceeded |
7 |
Execution timed out |
2047 ms |
2392 KB |
Time limit exceeded |
8 |
Execution timed out |
2081 ms |
2396 KB |
Time limit exceeded |
9 |
Execution timed out |
2009 ms |
2648 KB |
Time limit exceeded |
10 |
Execution timed out |
2054 ms |
2392 KB |
Time limit exceeded |
11 |
Execution timed out |
2020 ms |
2648 KB |
Time limit exceeded |
12 |
Execution timed out |
2037 ms |
2392 KB |
Time limit exceeded |
13 |
Execution timed out |
2033 ms |
3160 KB |
Time limit exceeded |
14 |
Execution timed out |
2066 ms |
2396 KB |
Time limit exceeded |
15 |
Execution timed out |
2045 ms |
2648 KB |
Time limit exceeded |
16 |
Correct |
38 ms |
2396 KB |
Output is correct |
17 |
Execution timed out |
2065 ms |
2396 KB |
Time limit exceeded |
18 |
Execution timed out |
2076 ms |
2396 KB |
Time limit exceeded |
19 |
Execution timed out |
2061 ms |
2396 KB |
Time limit exceeded |
20 |
Execution timed out |
2082 ms |
2396 KB |
Time limit exceeded |
21 |
Execution timed out |
2063 ms |
2652 KB |
Time limit exceeded |
22 |
Execution timed out |
2060 ms |
2652 KB |
Time limit exceeded |
23 |
Execution timed out |
2068 ms |
3676 KB |
Time limit exceeded |
24 |
Correct |
23 ms |
2396 KB |
Output is correct |
25 |
Execution timed out |
2066 ms |
2396 KB |
Time limit exceeded |
26 |
Execution timed out |
2031 ms |
2392 KB |
Time limit exceeded |
27 |
Execution timed out |
2021 ms |
2648 KB |
Time limit exceeded |
28 |
Execution timed out |
2083 ms |
3420 KB |
Time limit exceeded |
29 |
Execution timed out |
2060 ms |
2396 KB |
Time limit exceeded |
30 |
Execution timed out |
2066 ms |
2396 KB |
Time limit exceeded |
31 |
Execution timed out |
2075 ms |
2652 KB |
Time limit exceeded |
32 |
Execution timed out |
2077 ms |
3676 KB |
Time limit exceeded |
33 |
Correct |
31 ms |
2392 KB |
Output is correct |
34 |
Execution timed out |
2028 ms |
2392 KB |
Time limit exceeded |
35 |
Execution timed out |
2058 ms |
2396 KB |
Time limit exceeded |
36 |
Execution timed out |
2045 ms |
2392 KB |
Time limit exceeded |
37 |
Execution timed out |
2068 ms |
2652 KB |
Time limit exceeded |
38 |
Execution timed out |
2059 ms |
2652 KB |
Time limit exceeded |
39 |
Execution timed out |
2047 ms |
2396 KB |
Time limit exceeded |
40 |
Execution timed out |
2041 ms |
2392 KB |
Time limit exceeded |
41 |
Execution timed out |
2055 ms |
2392 KB |
Time limit exceeded |
42 |
Execution timed out |
2059 ms |
2392 KB |
Time limit exceeded |
43 |
Execution timed out |
2068 ms |
2396 KB |
Time limit exceeded |
44 |
Execution timed out |
2045 ms |
2392 KB |
Time limit exceeded |
45 |
Execution timed out |
2037 ms |
2648 KB |
Time limit exceeded |
46 |
Execution timed out |
2060 ms |
2652 KB |
Time limit exceeded |
47 |
Execution timed out |
2096 ms |
3932 KB |
Time limit exceeded |