#include <bits/stdc++.h>
using namespace std;
void just_do_it();
int main() {
#ifdef KAMIRULEZ
freopen("kamirulez.inp", "r", stdin);
freopen("kamirulez.out", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
just_do_it();
return 0;
}
const int maxN = 2e5 + 20;
int a[maxN * 2];
int cnt1[maxN];
int cnt2[maxN];
int N, R, K;
void simulate(int start, int lim, int cnt[]) {
for (int i = 1; i <= N; i++) {
cnt[i] = 0;
}
for (int i = 1; i <= start * 2 - 1; i++) {
if (a[i] >= lim) {
cnt[(i + 1) / 2]++;
}
}
if (K >= lim) {
cnt[start]++;
}
for (int i = start * 2; i <= N * 2 - 1; i++) {
if (a[i] >= lim) {
cnt[i / 2 + 1]++;
}
}
vector<int> free;
vector<int> holes;
for (int i = 1; i <= N; i++) {
if (cnt[i] == 2) {
if (!holes.empty()) {
cnt[holes.back()] = 1;
holes.pop_back();
}
else {
free.push_back(i);
}
cnt[i] = 1;
}
else {
if (cnt[1] == 1) {
free.push_back(i);
cnt[1] = 0;
}
if (cnt[i] == 0 && i > 1) {
holes.push_back(i);
}
}
}
reverse(free.begin(), free.end());
for (int i = N; i > 1 && !free.empty(); i--) {
if (cnt[i] == 0) {
free.pop_back();
cnt[i] = 1;
}
}
for (auto i: free) {
cnt[((i - 1) + N - R % N) % N + 1]++;
}
}
int solve(int start) {
simulate(start, K, cnt1);
simulate(start, K + 1, cnt2);
for (int i = 1; i <= N; i++) {
if (cnt1[i] != cnt2[i]) {
return i;
}
}
return -1;
}
void just_do_it() {
cin >> N >> R >> K;
for (int i = 1; i <= N * 2 - 1; i++) {
cin >> a[i];
}
if (N == 1) {
cout << 1;
return;
}
if (K == 1) {
cout << N;
return;
}
if (K == N * 2) {
cout << 2;
return;
}
pair<int, int> res = make_pair(N + 1, 0);
for (int i = 1; i <= N; i++) {
res = min(res, make_pair(solve(i), -i));
}
cout << -res.second;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
207 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
66 ms |
348 KB |
Output is correct |
4 |
Execution timed out |
2077 ms |
596 KB |
Time limit exceeded |
5 |
Execution timed out |
2065 ms |
3432 KB |
Time limit exceeded |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
25 ms |
340 KB |
Output is correct |
8 |
Execution timed out |
2080 ms |
596 KB |
Time limit exceeded |
9 |
Execution timed out |
2058 ms |
596 KB |
Time limit exceeded |
10 |
Correct |
58 ms |
340 KB |
Output is correct |
11 |
Execution timed out |
2068 ms |
724 KB |
Time limit exceeded |
12 |
Correct |
172 ms |
376 KB |
Output is correct |
13 |
Execution timed out |
2087 ms |
3024 KB |
Time limit exceeded |
14 |
Correct |
879 ms |
428 KB |
Output is correct |
15 |
Execution timed out |
2056 ms |
852 KB |
Time limit exceeded |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
69 ms |
340 KB |
Output is correct |
18 |
Correct |
90 ms |
360 KB |
Output is correct |
19 |
Correct |
320 ms |
400 KB |
Output is correct |
20 |
Correct |
901 ms |
432 KB |
Output is correct |
21 |
Execution timed out |
2045 ms |
724 KB |
Time limit exceeded |
22 |
Execution timed out |
2055 ms |
844 KB |
Time limit exceeded |
23 |
Execution timed out |
2069 ms |
3876 KB |
Time limit exceeded |
24 |
Correct |
3 ms |
340 KB |
Output is correct |
25 |
Correct |
23 ms |
372 KB |
Output is correct |
26 |
Correct |
522 ms |
480 KB |
Output is correct |
27 |
Execution timed out |
2071 ms |
852 KB |
Time limit exceeded |
28 |
Execution timed out |
2066 ms |
3116 KB |
Time limit exceeded |
29 |
Correct |
33 ms |
340 KB |
Output is correct |
30 |
Correct |
308 ms |
484 KB |
Output is correct |
31 |
Execution timed out |
2074 ms |
724 KB |
Time limit exceeded |
32 |
Execution timed out |
2073 ms |
4052 KB |
Time limit exceeded |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
67 ms |
340 KB |
Output is correct |
36 |
Correct |
103 ms |
392 KB |
Output is correct |
37 |
Execution timed out |
2091 ms |
724 KB |
Time limit exceeded |
38 |
Execution timed out |
2061 ms |
796 KB |
Time limit exceeded |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
19 ms |
376 KB |
Output is correct |
41 |
Correct |
73 ms |
384 KB |
Output is correct |
42 |
Correct |
103 ms |
392 KB |
Output is correct |
43 |
Correct |
432 ms |
468 KB |
Output is correct |
44 |
Correct |
1495 ms |
604 KB |
Output is correct |
45 |
Execution timed out |
2081 ms |
724 KB |
Time limit exceeded |
46 |
Execution timed out |
2078 ms |
724 KB |
Time limit exceeded |
47 |
Execution timed out |
2068 ms |
4144 KB |
Time limit exceeded |