#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
void solve(int N){
map<int, map<int, int> > m; vector<pair<int, int> > v;
int a[15000]; bool b = true;
int sol[15000]; m[0][1] = query(1, 2);
for (int i = 2; i < N; ++i){
m[i - 2][i] = query(i - 1, i + 1);
m[i - 1][i] = query(i, i + 1);
}
//a[0] < a[1]
a[0] = 0; a[1] = m[0][1];
for (int i = 2; i < N; ++i){
bool c = false;
for (int j = -1; j <= 1; ++j){
if (j == 0) continue;
a[i] = a[i - 1] + j * m[i - 1][i];
if (max(a[i - 2], max(a[i - 1], a[i])) - min(a[i - 2], min(a[i - 1], a[i])) == m[i - 2][i]){
c = true; break;
}
}
if (!c){
b = false; break;
}
}
for (int i = 0; i < N; ++i)
v.push_back({a[i], i});
sort(v.begin(), v.end()); int x, y;
for (int i = 0; i < N; ++i){
sol[v[i].second] = i + 1;
if (i + 1 == 1) x = v[i].second;
if (i + 1 == N) y = v[i].second;
}
if (!b || x > y){
a[0] = 0; a[1] = -m[0][1];
for (int i = 2; i < N; ++i){
for (int j = -1; j <= 1; ++j){
if (j == 0) continue;
a[i] = a[i - 1] + j * m[i - 1][i];
if (max(a[i - 2], max(a[i - 1], a[i])) - min(a[i - 2], min(a[i - 1], a[i])) == m[i - 2][i])
break;
}
}
v.clear();
for (int i = 0; i < N; ++i)
v.push_back({a[i], i});
sort(v.begin(), v.end());
for (int i = 0; i < N; ++i)
sol[v[i].second] = i + 1;
}
for (int i = 0; i < N; ++i)
answer(i + 1, sol[i]);
return;
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:37:17: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
37 | if (!b || x > y){
| ~~^~~
xylophone.cpp:37:17: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
404 KB |
Output is correct |
4 |
Correct |
2 ms |
328 KB |
Output is correct |
5 |
Correct |
3 ms |
328 KB |
Output is correct |
6 |
Correct |
3 ms |
328 KB |
Output is correct |
7 |
Correct |
2 ms |
328 KB |
Output is correct |
8 |
Correct |
2 ms |
328 KB |
Output is correct |
9 |
Correct |
3 ms |
328 KB |
Output is correct |
10 |
Correct |
3 ms |
328 KB |
Output is correct |
11 |
Correct |
3 ms |
328 KB |
Output is correct |
12 |
Correct |
3 ms |
416 KB |
Output is correct |
13 |
Correct |
3 ms |
328 KB |
Output is correct |
14 |
Correct |
3 ms |
404 KB |
Output is correct |
15 |
Correct |
3 ms |
424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
404 KB |
Output is correct |
4 |
Correct |
2 ms |
328 KB |
Output is correct |
5 |
Correct |
3 ms |
328 KB |
Output is correct |
6 |
Correct |
3 ms |
328 KB |
Output is correct |
7 |
Correct |
2 ms |
328 KB |
Output is correct |
8 |
Correct |
2 ms |
328 KB |
Output is correct |
9 |
Correct |
3 ms |
328 KB |
Output is correct |
10 |
Correct |
3 ms |
328 KB |
Output is correct |
11 |
Correct |
3 ms |
328 KB |
Output is correct |
12 |
Correct |
3 ms |
416 KB |
Output is correct |
13 |
Correct |
3 ms |
328 KB |
Output is correct |
14 |
Correct |
3 ms |
404 KB |
Output is correct |
15 |
Correct |
3 ms |
424 KB |
Output is correct |
16 |
Correct |
4 ms |
328 KB |
Output is correct |
17 |
Correct |
10 ms |
456 KB |
Output is correct |
18 |
Correct |
17 ms |
476 KB |
Output is correct |
19 |
Correct |
24 ms |
472 KB |
Output is correct |
20 |
Correct |
25 ms |
584 KB |
Output is correct |
21 |
Correct |
23 ms |
528 KB |
Output is correct |
22 |
Correct |
24 ms |
588 KB |
Output is correct |
23 |
Correct |
10 ms |
520 KB |
Output is correct |
24 |
Correct |
22 ms |
548 KB |
Output is correct |
25 |
Correct |
22 ms |
588 KB |
Output is correct |
26 |
Correct |
21 ms |
620 KB |
Output is correct |
27 |
Correct |
21 ms |
568 KB |
Output is correct |
28 |
Correct |
21 ms |
492 KB |
Output is correct |
29 |
Correct |
19 ms |
572 KB |
Output is correct |
30 |
Correct |
18 ms |
520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
404 KB |
Output is correct |
4 |
Correct |
2 ms |
328 KB |
Output is correct |
5 |
Correct |
3 ms |
328 KB |
Output is correct |
6 |
Correct |
3 ms |
328 KB |
Output is correct |
7 |
Correct |
2 ms |
328 KB |
Output is correct |
8 |
Correct |
2 ms |
328 KB |
Output is correct |
9 |
Correct |
3 ms |
328 KB |
Output is correct |
10 |
Correct |
3 ms |
328 KB |
Output is correct |
11 |
Correct |
3 ms |
328 KB |
Output is correct |
12 |
Correct |
3 ms |
416 KB |
Output is correct |
13 |
Correct |
3 ms |
328 KB |
Output is correct |
14 |
Correct |
3 ms |
404 KB |
Output is correct |
15 |
Correct |
3 ms |
424 KB |
Output is correct |
16 |
Correct |
4 ms |
328 KB |
Output is correct |
17 |
Correct |
10 ms |
456 KB |
Output is correct |
18 |
Correct |
17 ms |
476 KB |
Output is correct |
19 |
Correct |
24 ms |
472 KB |
Output is correct |
20 |
Correct |
25 ms |
584 KB |
Output is correct |
21 |
Correct |
23 ms |
528 KB |
Output is correct |
22 |
Correct |
24 ms |
588 KB |
Output is correct |
23 |
Correct |
10 ms |
520 KB |
Output is correct |
24 |
Correct |
22 ms |
548 KB |
Output is correct |
25 |
Correct |
22 ms |
588 KB |
Output is correct |
26 |
Correct |
21 ms |
620 KB |
Output is correct |
27 |
Correct |
21 ms |
568 KB |
Output is correct |
28 |
Correct |
21 ms |
492 KB |
Output is correct |
29 |
Correct |
19 ms |
572 KB |
Output is correct |
30 |
Correct |
18 ms |
520 KB |
Output is correct |
31 |
Correct |
49 ms |
740 KB |
Output is correct |
32 |
Correct |
59 ms |
984 KB |
Output is correct |
33 |
Correct |
86 ms |
1320 KB |
Output is correct |
34 |
Correct |
97 ms |
1424 KB |
Output is correct |
35 |
Correct |
97 ms |
1480 KB |
Output is correct |
36 |
Correct |
90 ms |
1388 KB |
Output is correct |
37 |
Correct |
95 ms |
1356 KB |
Output is correct |
38 |
Correct |
91 ms |
1476 KB |
Output is correct |
39 |
Correct |
86 ms |
1564 KB |
Output is correct |
40 |
Correct |
104 ms |
1368 KB |
Output is correct |
41 |
Correct |
105 ms |
1440 KB |
Output is correct |
42 |
Correct |
89 ms |
1444 KB |
Output is correct |
43 |
Correct |
93 ms |
1452 KB |
Output is correct |
44 |
Correct |
93 ms |
1544 KB |
Output is correct |
45 |
Correct |
65 ms |
1388 KB |
Output is correct |
46 |
Correct |
99 ms |
1452 KB |
Output is correct |
47 |
Correct |
79 ms |
1364 KB |
Output is correct |
48 |
Correct |
90 ms |
1420 KB |
Output is correct |
49 |
Correct |
83 ms |
1484 KB |
Output is correct |
50 |
Correct |
94 ms |
1464 KB |
Output is correct |
51 |
Correct |
76 ms |
1368 KB |
Output is correct |
52 |
Correct |
92 ms |
1344 KB |
Output is correct |
53 |
Correct |
96 ms |
1416 KB |
Output is correct |
54 |
Correct |
89 ms |
1344 KB |
Output is correct |
55 |
Correct |
100 ms |
1436 KB |
Output is correct |
56 |
Correct |
80 ms |
1468 KB |
Output is correct |
57 |
Correct |
107 ms |
1420 KB |
Output is correct |
58 |
Correct |
104 ms |
1452 KB |
Output is correct |
59 |
Correct |
75 ms |
1436 KB |
Output is correct |
60 |
Correct |
116 ms |
1408 KB |
Output is correct |