#include"xylophone.h"
#include<bits/stdc++.h>
using namespace std;
void solve(int n)
{
if (n == 2)
{
answer(1, 1), answer(2, 2);
return;
}
int d[5001], e[5001];
for (int i = 1; i <= n - 1; i++)
d[i] = query(i, i + 1);
for (int i = 1; i <= n - 2; i++)
e[i] = query(i, i + 2);
bool pp;
int ans[5001];
ans[1] = 1, ans[2] = ans[1] + d[1];
if (d[1] + d[2] == e[1])
ans[3] = ans[2] + d[2], pp = true;
else
ans[3] = ans[2] - d[2], pp = false;
for (int i = 4; i <= n; i++)
if (d[i - 2] + d[i - 1] == e[i - 2])
if (pp)
ans[i] = ans[i - 1] + d[i - 1];
else
ans[i] = ans[i - 1] - d[i - 1];
else
if (pp)
ans[i] = ans[i - 1] - d[i - 1], pp = false;
else
ans[i] = ans[i - 1] + d[i - 1], pp = true;
int mn = 1e9;
for (int i = 1; i <= n; i++)
mn = min(mn, ans[i]);
for (int i = 1; i <= n; i++)
ans[i] += -mn + 1;
bool ok;
for (int i = 1; i <= n; i++)
if (ans[i] == 1)
{
ok = true;
break;
}
else if (ans[i] == n)
{
ok = false;
break;
}
else;
if (!ok)
for (int i = 1; i <= n; i++)
ans[i] = n - ans[i] + 1;
for (int i = 1; i <= n; i++)
answer(i, ans[i]);
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:59:5: warning: 'ok' may be used uninitialized in this function [-Wmaybe-uninitialized]
if (!ok)
^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
248 KB |
Output is correct |
3 |
Correct |
6 ms |
380 KB |
Output is correct |
4 |
Correct |
6 ms |
248 KB |
Output is correct |
5 |
Correct |
6 ms |
248 KB |
Output is correct |
6 |
Correct |
6 ms |
248 KB |
Output is correct |
7 |
Correct |
7 ms |
248 KB |
Output is correct |
8 |
Correct |
6 ms |
376 KB |
Output is correct |
9 |
Correct |
7 ms |
376 KB |
Output is correct |
10 |
Correct |
6 ms |
248 KB |
Output is correct |
11 |
Correct |
6 ms |
248 KB |
Output is correct |
12 |
Correct |
7 ms |
248 KB |
Output is correct |
13 |
Correct |
6 ms |
412 KB |
Output is correct |
14 |
Correct |
7 ms |
248 KB |
Output is correct |
15 |
Correct |
7 ms |
248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
248 KB |
Output is correct |
3 |
Correct |
6 ms |
380 KB |
Output is correct |
4 |
Correct |
6 ms |
248 KB |
Output is correct |
5 |
Correct |
6 ms |
248 KB |
Output is correct |
6 |
Correct |
6 ms |
248 KB |
Output is correct |
7 |
Correct |
7 ms |
248 KB |
Output is correct |
8 |
Correct |
6 ms |
376 KB |
Output is correct |
9 |
Correct |
7 ms |
376 KB |
Output is correct |
10 |
Correct |
6 ms |
248 KB |
Output is correct |
11 |
Correct |
6 ms |
248 KB |
Output is correct |
12 |
Correct |
7 ms |
248 KB |
Output is correct |
13 |
Correct |
6 ms |
412 KB |
Output is correct |
14 |
Correct |
7 ms |
248 KB |
Output is correct |
15 |
Correct |
7 ms |
248 KB |
Output is correct |
16 |
Correct |
8 ms |
248 KB |
Output is correct |
17 |
Correct |
10 ms |
400 KB |
Output is correct |
18 |
Correct |
20 ms |
300 KB |
Output is correct |
19 |
Correct |
24 ms |
248 KB |
Output is correct |
20 |
Correct |
26 ms |
376 KB |
Output is correct |
21 |
Correct |
27 ms |
252 KB |
Output is correct |
22 |
Correct |
22 ms |
376 KB |
Output is correct |
23 |
Correct |
20 ms |
248 KB |
Output is correct |
24 |
Correct |
24 ms |
376 KB |
Output is correct |
25 |
Correct |
25 ms |
248 KB |
Output is correct |
26 |
Correct |
27 ms |
376 KB |
Output is correct |
27 |
Correct |
24 ms |
248 KB |
Output is correct |
28 |
Correct |
20 ms |
376 KB |
Output is correct |
29 |
Correct |
21 ms |
248 KB |
Output is correct |
30 |
Correct |
22 ms |
248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
248 KB |
Output is correct |
3 |
Correct |
6 ms |
380 KB |
Output is correct |
4 |
Correct |
6 ms |
248 KB |
Output is correct |
5 |
Correct |
6 ms |
248 KB |
Output is correct |
6 |
Correct |
6 ms |
248 KB |
Output is correct |
7 |
Correct |
7 ms |
248 KB |
Output is correct |
8 |
Correct |
6 ms |
376 KB |
Output is correct |
9 |
Correct |
7 ms |
376 KB |
Output is correct |
10 |
Correct |
6 ms |
248 KB |
Output is correct |
11 |
Correct |
6 ms |
248 KB |
Output is correct |
12 |
Correct |
7 ms |
248 KB |
Output is correct |
13 |
Correct |
6 ms |
412 KB |
Output is correct |
14 |
Correct |
7 ms |
248 KB |
Output is correct |
15 |
Correct |
7 ms |
248 KB |
Output is correct |
16 |
Correct |
8 ms |
248 KB |
Output is correct |
17 |
Correct |
10 ms |
400 KB |
Output is correct |
18 |
Correct |
20 ms |
300 KB |
Output is correct |
19 |
Correct |
24 ms |
248 KB |
Output is correct |
20 |
Correct |
26 ms |
376 KB |
Output is correct |
21 |
Correct |
27 ms |
252 KB |
Output is correct |
22 |
Correct |
22 ms |
376 KB |
Output is correct |
23 |
Correct |
20 ms |
248 KB |
Output is correct |
24 |
Correct |
24 ms |
376 KB |
Output is correct |
25 |
Correct |
25 ms |
248 KB |
Output is correct |
26 |
Correct |
27 ms |
376 KB |
Output is correct |
27 |
Correct |
24 ms |
248 KB |
Output is correct |
28 |
Correct |
20 ms |
376 KB |
Output is correct |
29 |
Correct |
21 ms |
248 KB |
Output is correct |
30 |
Correct |
22 ms |
248 KB |
Output is correct |
31 |
Correct |
42 ms |
376 KB |
Output is correct |
32 |
Correct |
58 ms |
376 KB |
Output is correct |
33 |
Correct |
85 ms |
380 KB |
Output is correct |
34 |
Correct |
94 ms |
376 KB |
Output is correct |
35 |
Correct |
91 ms |
376 KB |
Output is correct |
36 |
Correct |
95 ms |
376 KB |
Output is correct |
37 |
Correct |
91 ms |
376 KB |
Output is correct |
38 |
Correct |
91 ms |
376 KB |
Output is correct |
39 |
Correct |
98 ms |
376 KB |
Output is correct |
40 |
Correct |
93 ms |
376 KB |
Output is correct |
41 |
Correct |
87 ms |
376 KB |
Output is correct |
42 |
Correct |
81 ms |
376 KB |
Output is correct |
43 |
Correct |
86 ms |
376 KB |
Output is correct |
44 |
Correct |
103 ms |
380 KB |
Output is correct |
45 |
Correct |
88 ms |
376 KB |
Output is correct |
46 |
Correct |
97 ms |
376 KB |
Output is correct |
47 |
Correct |
93 ms |
376 KB |
Output is correct |
48 |
Correct |
98 ms |
376 KB |
Output is correct |
49 |
Correct |
96 ms |
376 KB |
Output is correct |
50 |
Correct |
80 ms |
336 KB |
Output is correct |
51 |
Correct |
98 ms |
376 KB |
Output is correct |
52 |
Correct |
82 ms |
376 KB |
Output is correct |
53 |
Correct |
105 ms |
376 KB |
Output is correct |
54 |
Correct |
89 ms |
376 KB |
Output is correct |
55 |
Correct |
100 ms |
376 KB |
Output is correct |
56 |
Correct |
88 ms |
376 KB |
Output is correct |
57 |
Correct |
101 ms |
376 KB |
Output is correct |
58 |
Correct |
52 ms |
324 KB |
Output is correct |
59 |
Correct |
89 ms |
376 KB |
Output is correct |
60 |
Correct |
90 ms |
376 KB |
Output is correct |