#include "xylophone.h"
#include "bits/stdc++.h"
using namespace std;
int my_query(int l, int r, vector <int> &a) {
int mx = -1e9, mn = 1e9;
for (int i = l; i <= r; ++i) {
mx = max(mx, a[i]);
mn = min(mn, a[i]);
}
return mx - mn;
}
void solve(int n) {
int r = n;
while (query(1, r) == n - 1) --r;
++r;
vector <int> a(n + 1, -1);
a[r] = n;
if (r != n) {
a[r + 1] = n - query(r, r + 1);
}
if (r != 1) {
a[r - 1] = n - query(r - 1, r);
}
for (int i = r - 2; i >= 1; --i) {
int x = query(i, i + 1);
int y = query(i, i + 2);
for (int z = 1; z <= n; ++z) {
a[i] = z;
if (my_query(i, i + 1, a) == x && my_query(i, i + 2, a) == y) {
break;
}
}
assert(a[i] != -1);
}
for (int i = r + 2; i <= n; ++i) {
int x = query(i - 1, i);
int y = query(i - 2, i);
for (int z = 1; z <= n; ++z) {
a[i] = z;
if (my_query(i - 1, i, a) == x && my_query(i - 2, i, a) == y) {
break;
}
}
assert(a[i] != -1);
}
for (int i = 1; i <= n; ++i) {
answer(i, a[i]);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
248 KB |
Output is correct |
2 |
Correct |
1 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
248 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
248 KB |
Output is correct |
6 |
Correct |
4 ms |
248 KB |
Output is correct |
7 |
Correct |
4 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
248 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
248 KB |
Output is correct |
12 |
Correct |
4 ms |
252 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
420 KB |
Output is correct |
15 |
Correct |
4 ms |
248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
248 KB |
Output is correct |
2 |
Correct |
1 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
248 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
248 KB |
Output is correct |
6 |
Correct |
4 ms |
248 KB |
Output is correct |
7 |
Correct |
4 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
248 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
248 KB |
Output is correct |
12 |
Correct |
4 ms |
252 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
420 KB |
Output is correct |
15 |
Correct |
4 ms |
248 KB |
Output is correct |
16 |
Correct |
4 ms |
248 KB |
Output is correct |
17 |
Correct |
11 ms |
248 KB |
Output is correct |
18 |
Correct |
22 ms |
376 KB |
Output is correct |
19 |
Correct |
23 ms |
376 KB |
Output is correct |
20 |
Correct |
23 ms |
248 KB |
Output is correct |
21 |
Correct |
25 ms |
420 KB |
Output is correct |
22 |
Correct |
21 ms |
248 KB |
Output is correct |
23 |
Correct |
19 ms |
248 KB |
Output is correct |
24 |
Correct |
21 ms |
376 KB |
Output is correct |
25 |
Correct |
31 ms |
248 KB |
Output is correct |
26 |
Correct |
12 ms |
316 KB |
Output is correct |
27 |
Correct |
31 ms |
248 KB |
Output is correct |
28 |
Correct |
32 ms |
248 KB |
Output is correct |
29 |
Correct |
24 ms |
248 KB |
Output is correct |
30 |
Correct |
25 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
248 KB |
Output is correct |
2 |
Correct |
1 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
248 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
248 KB |
Output is correct |
6 |
Correct |
4 ms |
248 KB |
Output is correct |
7 |
Correct |
4 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
248 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
248 KB |
Output is correct |
12 |
Correct |
4 ms |
252 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
420 KB |
Output is correct |
15 |
Correct |
4 ms |
248 KB |
Output is correct |
16 |
Correct |
4 ms |
248 KB |
Output is correct |
17 |
Correct |
11 ms |
248 KB |
Output is correct |
18 |
Correct |
22 ms |
376 KB |
Output is correct |
19 |
Correct |
23 ms |
376 KB |
Output is correct |
20 |
Correct |
23 ms |
248 KB |
Output is correct |
21 |
Correct |
25 ms |
420 KB |
Output is correct |
22 |
Correct |
21 ms |
248 KB |
Output is correct |
23 |
Correct |
19 ms |
248 KB |
Output is correct |
24 |
Correct |
21 ms |
376 KB |
Output is correct |
25 |
Correct |
31 ms |
248 KB |
Output is correct |
26 |
Correct |
12 ms |
316 KB |
Output is correct |
27 |
Correct |
31 ms |
248 KB |
Output is correct |
28 |
Correct |
32 ms |
248 KB |
Output is correct |
29 |
Correct |
24 ms |
248 KB |
Output is correct |
30 |
Correct |
25 ms |
376 KB |
Output is correct |
31 |
Correct |
59 ms |
376 KB |
Output is correct |
32 |
Correct |
72 ms |
296 KB |
Output is correct |
33 |
Incorrect |
146 ms |
376 KB |
Wrong Answer [2] |
34 |
Halted |
0 ms |
0 KB |
- |