#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k, l) for(int i = (j); i < (k); i += (l))
#define FORD(i, j, k, l) for(int i = (j); i >= (k); i += (l))
#define REP(i, n) FOR(i, 0, n, 1)
#define REPD(i, n) FORD(i, n, 0, 1)
typedef long long ll;
static int A[5000];
void solve(int N) {
vector<array<int, 2>> nx(N + 1);
FOR(i, 1, N + 1, 1){
FOR(j, 1, 3, 1){
if(i + j < N + 1){
nx[i][j - 1] = query(i, i + j);
}
}
}
auto construct = [&](int f, int s){ // if I know prev 2, determines next; brute first. brute second as first + diff or first - diff; validate seq later
vector<int> res(N + 1);
res[1] = f;
res[2] = s;
FOR(i, 3, N + 1, 1){
if(res[i - 2] > res[i - 1]){
if(nx[i - 2][0] + nx[i - 1][0] == nx[i - 2][1]){
res[i] = res[i - 1] - nx[i - 1][0];
}
else{
res[i] = res[i - 1] + nx[i - 1][0];
}
}
else{
if(nx[i - 2][0] + nx[i - 1][0] == nx[i - 2][1]){
res[i] = res[i - 1] + nx[i - 1][0];
}
else{
res[i] = res[i - 1] - nx[i - 1][0];
}
}
}
return res;
};
auto validate = [&](vector<int> &res){
FOR(i, 1, N + 1, 1){
if(res[i] > N || res[i] < 1)
return false;
}
vector<bool> used(N + 1, false);
FOR(i, 1, N + 1, 1){
used[res[i]] = true;
}
FOR(i, 1, N + 1, 1){
if(used[i] == false)
return false;
}
int f = 0;
int s = 0;
FOR(i, 1, N + 1, 1){
if(res[i] == 1)
f = i;
if(res[i] == N)
s = i;
}
if(f > s)
return false;
return true;
};
vector<int> res;
FOR(i, 1, N + 1, 1){
res = construct(i, i + nx[1][0]);
if(validate(res))
break;
res = construct(i, i - nx[1][0]);
if(validate(res))
break;
}
FOR(i, 1, N + 1, 1){
answer(i, res[i]);
}
}
Compilation message
xylophone.cpp:9:12: warning: 'A' defined but not used [-Wunused-variable]
9 | static int A[5000];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
3 ms |
200 KB |
Output is correct |
4 |
Correct |
2 ms |
200 KB |
Output is correct |
5 |
Correct |
5 ms |
200 KB |
Output is correct |
6 |
Correct |
3 ms |
200 KB |
Output is correct |
7 |
Correct |
4 ms |
200 KB |
Output is correct |
8 |
Correct |
4 ms |
200 KB |
Output is correct |
9 |
Correct |
6 ms |
200 KB |
Output is correct |
10 |
Correct |
3 ms |
200 KB |
Output is correct |
11 |
Correct |
3 ms |
200 KB |
Output is correct |
12 |
Correct |
3 ms |
200 KB |
Output is correct |
13 |
Correct |
3 ms |
200 KB |
Output is correct |
14 |
Correct |
2 ms |
200 KB |
Output is correct |
15 |
Correct |
4 ms |
200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
3 ms |
200 KB |
Output is correct |
4 |
Correct |
2 ms |
200 KB |
Output is correct |
5 |
Correct |
5 ms |
200 KB |
Output is correct |
6 |
Correct |
3 ms |
200 KB |
Output is correct |
7 |
Correct |
4 ms |
200 KB |
Output is correct |
8 |
Correct |
4 ms |
200 KB |
Output is correct |
9 |
Correct |
6 ms |
200 KB |
Output is correct |
10 |
Correct |
3 ms |
200 KB |
Output is correct |
11 |
Correct |
3 ms |
200 KB |
Output is correct |
12 |
Correct |
3 ms |
200 KB |
Output is correct |
13 |
Correct |
3 ms |
200 KB |
Output is correct |
14 |
Correct |
2 ms |
200 KB |
Output is correct |
15 |
Correct |
4 ms |
200 KB |
Output is correct |
16 |
Correct |
6 ms |
200 KB |
Output is correct |
17 |
Correct |
10 ms |
200 KB |
Output is correct |
18 |
Correct |
21 ms |
200 KB |
Output is correct |
19 |
Correct |
28 ms |
200 KB |
Output is correct |
20 |
Correct |
28 ms |
280 KB |
Output is correct |
21 |
Correct |
25 ms |
280 KB |
Output is correct |
22 |
Correct |
25 ms |
200 KB |
Output is correct |
23 |
Correct |
26 ms |
280 KB |
Output is correct |
24 |
Correct |
37 ms |
276 KB |
Output is correct |
25 |
Correct |
24 ms |
200 KB |
Output is correct |
26 |
Correct |
33 ms |
284 KB |
Output is correct |
27 |
Correct |
24 ms |
200 KB |
Output is correct |
28 |
Correct |
34 ms |
276 KB |
Output is correct |
29 |
Correct |
25 ms |
200 KB |
Output is correct |
30 |
Correct |
17 ms |
200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
3 ms |
200 KB |
Output is correct |
4 |
Correct |
2 ms |
200 KB |
Output is correct |
5 |
Correct |
5 ms |
200 KB |
Output is correct |
6 |
Correct |
3 ms |
200 KB |
Output is correct |
7 |
Correct |
4 ms |
200 KB |
Output is correct |
8 |
Correct |
4 ms |
200 KB |
Output is correct |
9 |
Correct |
6 ms |
200 KB |
Output is correct |
10 |
Correct |
3 ms |
200 KB |
Output is correct |
11 |
Correct |
3 ms |
200 KB |
Output is correct |
12 |
Correct |
3 ms |
200 KB |
Output is correct |
13 |
Correct |
3 ms |
200 KB |
Output is correct |
14 |
Correct |
2 ms |
200 KB |
Output is correct |
15 |
Correct |
4 ms |
200 KB |
Output is correct |
16 |
Correct |
6 ms |
200 KB |
Output is correct |
17 |
Correct |
10 ms |
200 KB |
Output is correct |
18 |
Correct |
21 ms |
200 KB |
Output is correct |
19 |
Correct |
28 ms |
200 KB |
Output is correct |
20 |
Correct |
28 ms |
280 KB |
Output is correct |
21 |
Correct |
25 ms |
280 KB |
Output is correct |
22 |
Correct |
25 ms |
200 KB |
Output is correct |
23 |
Correct |
26 ms |
280 KB |
Output is correct |
24 |
Correct |
37 ms |
276 KB |
Output is correct |
25 |
Correct |
24 ms |
200 KB |
Output is correct |
26 |
Correct |
33 ms |
284 KB |
Output is correct |
27 |
Correct |
24 ms |
200 KB |
Output is correct |
28 |
Correct |
34 ms |
276 KB |
Output is correct |
29 |
Correct |
25 ms |
200 KB |
Output is correct |
30 |
Correct |
17 ms |
200 KB |
Output is correct |
31 |
Correct |
65 ms |
300 KB |
Output is correct |
32 |
Correct |
145 ms |
316 KB |
Output is correct |
33 |
Correct |
175 ms |
336 KB |
Output is correct |
34 |
Correct |
268 ms |
352 KB |
Output is correct |
35 |
Correct |
261 ms |
328 KB |
Output is correct |
36 |
Correct |
108 ms |
308 KB |
Output is correct |
37 |
Correct |
196 ms |
348 KB |
Output is correct |
38 |
Correct |
84 ms |
308 KB |
Output is correct |
39 |
Correct |
142 ms |
328 KB |
Output is correct |
40 |
Correct |
155 ms |
328 KB |
Output is correct |
41 |
Correct |
376 ms |
348 KB |
Output is correct |
42 |
Correct |
105 ms |
320 KB |
Output is correct |
43 |
Correct |
205 ms |
352 KB |
Output is correct |
44 |
Correct |
85 ms |
452 KB |
Output is correct |
45 |
Correct |
192 ms |
348 KB |
Output is correct |
46 |
Correct |
344 ms |
352 KB |
Output is correct |
47 |
Correct |
280 ms |
328 KB |
Output is correct |
48 |
Correct |
123 ms |
328 KB |
Output is correct |
49 |
Correct |
270 ms |
308 KB |
Output is correct |
50 |
Correct |
286 ms |
308 KB |
Output is correct |
51 |
Correct |
124 ms |
352 KB |
Output is correct |
52 |
Correct |
142 ms |
308 KB |
Output is correct |
53 |
Correct |
318 ms |
356 KB |
Output is correct |
54 |
Correct |
270 ms |
320 KB |
Output is correct |
55 |
Correct |
243 ms |
352 KB |
Output is correct |
56 |
Correct |
298 ms |
328 KB |
Output is correct |
57 |
Correct |
301 ms |
372 KB |
Output is correct |
58 |
Correct |
355 ms |
328 KB |
Output is correct |
59 |
Correct |
238 ms |
308 KB |
Output is correct |
60 |
Correct |
203 ms |
308 KB |
Output is correct |