#include "xylophone.h"
#include <cmath>
using namespace std;
void solve(int n) {
int a[n + 1];
int l = 1, r = n;
while(r - l > 1) {
int m = (l + r) / 2;
if(query(1, m) >= n - 1) {
r = m;
}
else {
l = m;
}
}
int mxid = r;
a[mxid] = n;
if(mxid > 1) {
a[mxid - 1] = a[mxid] - query(mxid - 1, mxid);
}
if(mxid + 1 <= n) {
a[mxid + 1] = a[mxid] - query(mxid, mxid + 1);
}
for(int i = mxid + 2; i <= n; ++i) {
int p = query(i - 1, i);
int val1 = a[i - 1] - p;
int val2 = a[i - 1] + p;
if(val1 < 1) {
a[i] = val2;
continue;
}
if(val2 >= n) {
a[i] = val1;
continue;
}
int t = query(i - 2, i);
if(abs(a[i - 1] - a[i - 2]) + p == t) {
if(a[i - 2] < a[i - 1]) {
a[i] = val2;
}
else {
a[i] = val1;
}
}
else {
if(a[i - 2] < a[i - 1]) {
a[i] = val1;
}
else {
a[i] = val2;
}
}
}
for(int i = mxid - 2; i >= 1; --i) {
int p = query(i, i + 1);
int val1 = a[i + 1] - p;
int val2 = a[i + 1] + p;
if(val1 < 1) {
a[i] = val2;
continue;
}
if(val2 >= n) {
a[i] = val1;
continue;
}
int t = query(i, i + 2);
if(abs(a[i + 1] - a[i + 2]) + p == t) {
if(a[i + 1] < a[i + 2]) {
a[i] = val1;
}
else {
a[i] = val2;
}
}
else {
if(a[i + 1] < a[i + 2]) {
a[i] = val2;
}
else {
a[i] = val1;
}
}
}
for(int i = 1; i <= n; ++i) {
answer(i, a[i]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
268 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
268 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
4 ms |
256 KB |
Output is correct |
17 |
Correct |
7 ms |
256 KB |
Output is correct |
18 |
Correct |
11 ms |
256 KB |
Output is correct |
19 |
Correct |
15 ms |
256 KB |
Output is correct |
20 |
Correct |
21 ms |
256 KB |
Output is correct |
21 |
Correct |
16 ms |
256 KB |
Output is correct |
22 |
Correct |
14 ms |
360 KB |
Output is correct |
23 |
Correct |
22 ms |
256 KB |
Output is correct |
24 |
Correct |
18 ms |
256 KB |
Output is correct |
25 |
Correct |
17 ms |
256 KB |
Output is correct |
26 |
Correct |
23 ms |
256 KB |
Output is correct |
27 |
Correct |
15 ms |
256 KB |
Output is correct |
28 |
Correct |
14 ms |
256 KB |
Output is correct |
29 |
Correct |
11 ms |
256 KB |
Output is correct |
30 |
Correct |
13 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
268 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
4 ms |
256 KB |
Output is correct |
17 |
Correct |
7 ms |
256 KB |
Output is correct |
18 |
Correct |
11 ms |
256 KB |
Output is correct |
19 |
Correct |
15 ms |
256 KB |
Output is correct |
20 |
Correct |
21 ms |
256 KB |
Output is correct |
21 |
Correct |
16 ms |
256 KB |
Output is correct |
22 |
Correct |
14 ms |
360 KB |
Output is correct |
23 |
Correct |
22 ms |
256 KB |
Output is correct |
24 |
Correct |
18 ms |
256 KB |
Output is correct |
25 |
Correct |
17 ms |
256 KB |
Output is correct |
26 |
Correct |
23 ms |
256 KB |
Output is correct |
27 |
Correct |
15 ms |
256 KB |
Output is correct |
28 |
Correct |
14 ms |
256 KB |
Output is correct |
29 |
Correct |
11 ms |
256 KB |
Output is correct |
30 |
Correct |
13 ms |
256 KB |
Output is correct |
31 |
Correct |
28 ms |
364 KB |
Output is correct |
32 |
Correct |
37 ms |
364 KB |
Output is correct |
33 |
Correct |
49 ms |
376 KB |
Output is correct |
34 |
Correct |
58 ms |
364 KB |
Output is correct |
35 |
Correct |
92 ms |
364 KB |
Output is correct |
36 |
Incorrect |
73 ms |
364 KB |
Wrong Answer [2] |
37 |
Halted |
0 ms |
0 KB |
- |