#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
void solve(int n) {
int t[5002];
memset(t, 0, sizeof t);
int q[5][5002];
memset(q, 0, sizeof q);
q[0][2] = query(1, 2);
t[2] = q[0][2];
int e = min(t[1], t[2]);
for (int i = 3; i <= n; i ++) {
q[0][i] = query(i-1, i);
q[1][i] = query(i-2, i);
if (t[i-2] < t[i-1]) {
if (q[0][i] == q[1][i] || q[0][i-1] == q[1][i]) t[i] = t[i-1] - q[0][i];
else t[i] = t[i-1] + q[0][i];
}
else {
if (q[0][i] == q[1][i] || q[0][i-1] == q[1][i]) t[i] = t[i-1] + q[0][i];
else t[i] = t[i-1] - q[0][i];
}
e = min(e, t[i]);
}
int bio[5002];
memset(bio, 0, sizeof bio);
int p = 0;
int ne = 0;
for (int i = 1; i <= n; i ++) {
t[i] -= e-1;
if (t[i] >= 1 && t[i] <= n) bio[t[i]] ++;
if (t[i] == 1) p = 1;
if (t[i] == n && p == 0) {
ne = 1;
}
}
int da = 1;
for (int i = 1; i <= n; i ++) {
if (bio[i] != 1) {
da = 0;
break;
}
}
if (da == 1 && ne == 0) {
for (int i = 1; i <= n; i ++) {
answer(i, t[i]);
}
return;
}
memset(t, 0, sizeof t);
t[2] = -q[0][2];
e = min(t[1], t[2]);
for (int i = 3; i <= n; i ++) {
if (t[i-2] < t[i-1]) {
if (q[0][i] == q[1][i] || q[0][i-1] == q[1][i]) t[i] = t[i-1] - q[0][i];
else t[i] = t[i-1] + q[0][i];
}
else {
if (q[0][i] == q[1][i] || q[0][i-1] == q[1][i]) t[i] = t[i-1] + q[0][i];
else t[i] = t[i-1] - q[0][i];
}
e = min(e, t[i]);
}
memset(bio, 0, sizeof bio);
p = 0;
ne = 0;
for (int i = 1; i <= n; i ++) {
t[i] -= e-1;
if (t[i] >= 1 && t[i] <= n) bio[t[i]] ++;
if (t[i] == 1) p = 1;
if (t[i] == n && p == 0) {
ne = 1;
}
}
da = 1;
for (int i = 1; i <= n; i ++) {
if (bio[i] != 1) {
da = 0;
break;
}
}
if (da == 1 && ne == 0) {
for (int i = 1; i <= n; i ++) {
answer(i, t[i]);
}
return;
}
assert(0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
520 KB |
Output is correct |
3 |
Correct |
2 ms |
432 KB |
Output is correct |
4 |
Correct |
4 ms |
380 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
4 ms |
504 KB |
Output is correct |
8 |
Correct |
4 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
4 ms |
504 KB |
Output is correct |
11 |
Correct |
4 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
504 KB |
Output is correct |
14 |
Correct |
4 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
520 KB |
Output is correct |
3 |
Correct |
2 ms |
432 KB |
Output is correct |
4 |
Correct |
4 ms |
380 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
4 ms |
504 KB |
Output is correct |
8 |
Correct |
4 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
4 ms |
504 KB |
Output is correct |
11 |
Correct |
4 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
504 KB |
Output is correct |
14 |
Correct |
4 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
8 ms |
376 KB |
Output is correct |
17 |
Correct |
13 ms |
432 KB |
Output is correct |
18 |
Correct |
17 ms |
436 KB |
Output is correct |
19 |
Correct |
22 ms |
376 KB |
Output is correct |
20 |
Correct |
22 ms |
376 KB |
Output is correct |
21 |
Correct |
18 ms |
504 KB |
Output is correct |
22 |
Correct |
22 ms |
376 KB |
Output is correct |
23 |
Correct |
22 ms |
504 KB |
Output is correct |
24 |
Correct |
19 ms |
504 KB |
Output is correct |
25 |
Correct |
24 ms |
552 KB |
Output is correct |
26 |
Correct |
27 ms |
504 KB |
Output is correct |
27 |
Correct |
21 ms |
376 KB |
Output is correct |
28 |
Correct |
12 ms |
520 KB |
Output is correct |
29 |
Correct |
25 ms |
504 KB |
Output is correct |
30 |
Correct |
25 ms |
432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
520 KB |
Output is correct |
3 |
Correct |
2 ms |
432 KB |
Output is correct |
4 |
Correct |
4 ms |
380 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
4 ms |
504 KB |
Output is correct |
8 |
Correct |
4 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
4 ms |
504 KB |
Output is correct |
11 |
Correct |
4 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
504 KB |
Output is correct |
14 |
Correct |
4 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
8 ms |
376 KB |
Output is correct |
17 |
Correct |
13 ms |
432 KB |
Output is correct |
18 |
Correct |
17 ms |
436 KB |
Output is correct |
19 |
Correct |
22 ms |
376 KB |
Output is correct |
20 |
Correct |
22 ms |
376 KB |
Output is correct |
21 |
Correct |
18 ms |
504 KB |
Output is correct |
22 |
Correct |
22 ms |
376 KB |
Output is correct |
23 |
Correct |
22 ms |
504 KB |
Output is correct |
24 |
Correct |
19 ms |
504 KB |
Output is correct |
25 |
Correct |
24 ms |
552 KB |
Output is correct |
26 |
Correct |
27 ms |
504 KB |
Output is correct |
27 |
Correct |
21 ms |
376 KB |
Output is correct |
28 |
Correct |
12 ms |
520 KB |
Output is correct |
29 |
Correct |
25 ms |
504 KB |
Output is correct |
30 |
Correct |
25 ms |
432 KB |
Output is correct |
31 |
Correct |
44 ms |
504 KB |
Output is correct |
32 |
Correct |
64 ms |
440 KB |
Output is correct |
33 |
Correct |
62 ms |
376 KB |
Output is correct |
34 |
Correct |
88 ms |
436 KB |
Output is correct |
35 |
Correct |
121 ms |
512 KB |
Output is correct |
36 |
Correct |
99 ms |
444 KB |
Output is correct |
37 |
Correct |
99 ms |
436 KB |
Output is correct |
38 |
Correct |
81 ms |
432 KB |
Output is correct |
39 |
Correct |
86 ms |
432 KB |
Output is correct |
40 |
Correct |
77 ms |
552 KB |
Output is correct |
41 |
Correct |
86 ms |
504 KB |
Output is correct |
42 |
Correct |
107 ms |
376 KB |
Output is correct |
43 |
Correct |
106 ms |
504 KB |
Output is correct |
44 |
Correct |
108 ms |
436 KB |
Output is correct |
45 |
Correct |
99 ms |
376 KB |
Output is correct |
46 |
Correct |
102 ms |
504 KB |
Output is correct |
47 |
Correct |
108 ms |
508 KB |
Output is correct |
48 |
Correct |
98 ms |
504 KB |
Output is correct |
49 |
Correct |
104 ms |
432 KB |
Output is correct |
50 |
Correct |
102 ms |
432 KB |
Output is correct |
51 |
Correct |
53 ms |
440 KB |
Output is correct |
52 |
Correct |
117 ms |
504 KB |
Output is correct |
53 |
Correct |
107 ms |
504 KB |
Output is correct |
54 |
Correct |
98 ms |
568 KB |
Output is correct |
55 |
Correct |
94 ms |
432 KB |
Output is correct |
56 |
Correct |
91 ms |
556 KB |
Output is correct |
57 |
Correct |
55 ms |
436 KB |
Output is correct |
58 |
Correct |
90 ms |
432 KB |
Output is correct |
59 |
Correct |
54 ms |
504 KB |
Output is correct |
60 |
Correct |
106 ms |
432 KB |
Output is correct |