#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
static int ans[5001], pos[5001];
static int a[5001], b[5001];
static int n;
void print(){
for (int i = 1; i <= n; i++){
// cout << ans[i] << " ";
answer(i, ans[i]);
}
// cout << "\n";
}
void solve(int nn) {
n = nn;
// int value = query(1, N);
// for(int i = 1; i <= N; i++) {
// answer(i, i);
// }
for (int i = 1; i < n; i++){
a[i] = query(i, i + 1);
}
for (int i = 1; i < n - 1; i++){
b[i] = query(i, i + 2);
}
for (int i = 1; i <= n; i++){
ans[1] = i;
if (i + a[1] <= n){
ans[2] = i + a[1];
bool seen = false;
bool good = true;
for (int j = 3; j <= n; j++){
if (a[j - 2] + a[j - 1] == b[j - 2]) {
if (ans[j - 1] > ans[j - 2]){
ans[j] = ans[j - 1] + a[j - 1];
} else {
ans[j] = ans[j - 1] - a[j - 1];
}
} else {
if (ans[j - 1] > ans[j - 2]){
ans[j] = ans[j - 1] - a[j - 1];
} else {
ans[j] = ans[j - 1] + a[j - 1];
}
}
if (ans[j] < 1 || ans[j] > n){
good = false;
}
}
for (int j = 1; j <= n; j++){
if (ans[j] == 1) seen = true;
if (ans[j] == n && !seen) good = false;
}
vector <int> st(n + 1, 0);
for (int i = 1; i <= n; i++){
if (ans[i] <= 0 || ans[i] > n) continue;
st[ans[i]]++;
if (st[ans[i]] > 1) good = false;
}
if (good){
print();
return;
}
}
if (i - a[1] >= 1){
ans[2] = i - a[1];
bool seen = false;
bool good = true;
for (int j = 3; j <= n; j++){
if (a[j - 2] + a[j - 1] == b[j - 2]) {
if (ans[j - 1] > ans[j - 2]){
ans[j] = ans[j - 1] + a[j - 1];
} else {
ans[j] = ans[j - 1] - a[j - 1];
}
} else {
if (ans[j - 1] > ans[j - 2]){
ans[j] = ans[j - 1] - a[j - 1];
} else {
ans[j] = ans[j - 1] + a[j - 1];
}
}
if (ans[j] < 1 || ans[j] > n){
good = false;
}
}
for (int j = 1; j <= n; j++){
if (ans[j] == 1) seen = true;
if (ans[j] == n && !seen) good = false;
}
vector <int> st(n + 1, 0);
for (int i = 1; i <= n; i++){
if (ans[i] <= 0 || ans[i] > n) continue;
st[ans[i]]++;
if (st[ans[i]] > 1) good = false;
}
if (good){
print();
return;
}
}
}
}
Compilation message
xylophone.cpp:5:23: warning: 'pos' defined but not used [-Wunused-variable]
5 | static int ans[5001], pos[5001];
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
2 ms |
304 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
3 ms |
308 KB |
Output is correct |
6 |
Correct |
2 ms |
304 KB |
Output is correct |
7 |
Correct |
2 ms |
308 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
308 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
304 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
2 ms |
304 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
3 ms |
308 KB |
Output is correct |
6 |
Correct |
2 ms |
304 KB |
Output is correct |
7 |
Correct |
2 ms |
308 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
308 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
304 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
9 ms |
304 KB |
Output is correct |
18 |
Correct |
12 ms |
208 KB |
Output is correct |
19 |
Correct |
28 ms |
296 KB |
Output is correct |
20 |
Correct |
18 ms |
312 KB |
Output is correct |
21 |
Correct |
21 ms |
308 KB |
Output is correct |
22 |
Correct |
21 ms |
428 KB |
Output is correct |
23 |
Correct |
12 ms |
312 KB |
Output is correct |
24 |
Correct |
22 ms |
208 KB |
Output is correct |
25 |
Correct |
11 ms |
208 KB |
Output is correct |
26 |
Correct |
21 ms |
312 KB |
Output is correct |
27 |
Correct |
12 ms |
208 KB |
Output is correct |
28 |
Correct |
19 ms |
304 KB |
Output is correct |
29 |
Correct |
26 ms |
308 KB |
Output is correct |
30 |
Correct |
18 ms |
304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
2 ms |
304 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
3 ms |
308 KB |
Output is correct |
6 |
Correct |
2 ms |
304 KB |
Output is correct |
7 |
Correct |
2 ms |
308 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
308 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
304 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
9 ms |
304 KB |
Output is correct |
18 |
Correct |
12 ms |
208 KB |
Output is correct |
19 |
Correct |
28 ms |
296 KB |
Output is correct |
20 |
Correct |
18 ms |
312 KB |
Output is correct |
21 |
Correct |
21 ms |
308 KB |
Output is correct |
22 |
Correct |
21 ms |
428 KB |
Output is correct |
23 |
Correct |
12 ms |
312 KB |
Output is correct |
24 |
Correct |
22 ms |
208 KB |
Output is correct |
25 |
Correct |
11 ms |
208 KB |
Output is correct |
26 |
Correct |
21 ms |
312 KB |
Output is correct |
27 |
Correct |
12 ms |
208 KB |
Output is correct |
28 |
Correct |
19 ms |
304 KB |
Output is correct |
29 |
Correct |
26 ms |
308 KB |
Output is correct |
30 |
Correct |
18 ms |
304 KB |
Output is correct |
31 |
Correct |
31 ms |
328 KB |
Output is correct |
32 |
Correct |
147 ms |
292 KB |
Output is correct |
33 |
Correct |
107 ms |
356 KB |
Output is correct |
34 |
Correct |
271 ms |
456 KB |
Output is correct |
35 |
Correct |
194 ms |
360 KB |
Output is correct |
36 |
Correct |
80 ms |
308 KB |
Output is correct |
37 |
Correct |
165 ms |
436 KB |
Output is correct |
38 |
Correct |
55 ms |
304 KB |
Output is correct |
39 |
Correct |
106 ms |
360 KB |
Output is correct |
40 |
Correct |
208 ms |
364 KB |
Output is correct |
41 |
Correct |
218 ms |
308 KB |
Output is correct |
42 |
Correct |
87 ms |
324 KB |
Output is correct |
43 |
Correct |
170 ms |
428 KB |
Output is correct |
44 |
Correct |
72 ms |
436 KB |
Output is correct |
45 |
Correct |
104 ms |
364 KB |
Output is correct |
46 |
Correct |
267 ms |
360 KB |
Output is correct |
47 |
Correct |
244 ms |
356 KB |
Output is correct |
48 |
Correct |
89 ms |
304 KB |
Output is correct |
49 |
Correct |
235 ms |
368 KB |
Output is correct |
50 |
Correct |
272 ms |
300 KB |
Output is correct |
51 |
Correct |
110 ms |
304 KB |
Output is correct |
52 |
Correct |
75 ms |
344 KB |
Output is correct |
53 |
Correct |
396 ms |
364 KB |
Output is correct |
54 |
Correct |
333 ms |
292 KB |
Output is correct |
55 |
Correct |
347 ms |
360 KB |
Output is correct |
56 |
Correct |
121 ms |
300 KB |
Output is correct |
57 |
Correct |
309 ms |
360 KB |
Output is correct |
58 |
Correct |
136 ms |
456 KB |
Output is correct |
59 |
Correct |
206 ms |
308 KB |
Output is correct |
60 |
Correct |
165 ms |
300 KB |
Output is correct |