#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
const int maxn = 5e3+10;
int n;
int num[maxn];
int dif[maxn][maxn];
bool maior[maxn];
void getQ(void)
{
for (int i = 1; i < n; i++)
{
dif[i][i+1] = query(i, i+1);
if (i < n-1) dif[i][i+2] = query(i, i+2);
}
}
void getMaior(void)
{
for (int i = 3; i <= n; i++)
{
if (!maior[i-1])
{
if (dif[i-2][i-1] == dif[i-2][i]) maior[i] = 1;
else if (dif[i-2][i-1] > dif[i-2][i]) maior[i] = 0;
else
{
if (dif[i-2][i] > dif[i-1][i]) maior[i] = 0;
else maior[i] = 1;
}
}
else
{
if (dif[i-2][i-1] == dif[i-2][i]) maior[i] = 0;
else if (dif[i-2][i-1] > dif[i-2][i]) maior[i] = 1;
else
{
if (dif[i-2][i] > dif[i-1][i]) maior[i] = 1;
else maior[i] = 0;
}
}
}
}
void getNumbers(void)
{
int ind;
for (int i = 1; i <= n; i++)
{
if (!maior[i]) continue;
int x = dif[i-1][i];
bool ok = 1;
for (int j = i-1; j > 1; j--)
{
if (maior[j]) x += dif[j-1][j];
else x -= dif[j-1][j];
if (x < 0) ok = 0;
}
if (!ok) continue;
if (maior[i+1]) continue;
x = dif[i][i+1];
ok = 1;
for (int j = i+2; j <= n; j++)
{
if (maior[j]) x -= dif[j-1][j];
else x += dif[j-1][j];
if (x < 0) ok = 0;
}
if (ok)
{
ind = i;
break;
}
}
num[ind] = n;
for (int i = ind-1; i >= 1; i--)
{
if (maior[i+1]) num[i] = num[i+1]-dif[i][i+1];
else num[i] = num[i+1]+dif[i][i+1];
}
for (int i = ind+1; i <= n; i++)
{
if (maior[i]) num[i] = num[i-1]+dif[i-1][i];
else num[i] = num[i-1]-dif[i-1][i];
}
}
void solve(int N)
{
n = N;
getQ();
maior[1] = maior[2] = 1;
getMaior();
getNumbers();
bool get1 = 0, ok = 1;
for (int i = 1; i <= n; i++)
{
if (num[i] == 1) get1 = 1;
if (num[i] == n && !get1) ok = 0;
}
if (!ok)
{
maior[2] = 0;
getMaior();
getNumbers();
}
for (int i = 1; i <= n; i++)
answer(i, num[i]);
}
Compilation message
xylophone.cpp: In function 'void getNumbers()':
xylophone.cpp:52:6: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
int ind;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
4 ms |
804 KB |
Output is correct |
5 |
Correct |
3 ms |
792 KB |
Output is correct |
6 |
Correct |
4 ms |
680 KB |
Output is correct |
7 |
Correct |
3 ms |
632 KB |
Output is correct |
8 |
Correct |
4 ms |
680 KB |
Output is correct |
9 |
Correct |
3 ms |
712 KB |
Output is correct |
10 |
Correct |
4 ms |
632 KB |
Output is correct |
11 |
Correct |
3 ms |
704 KB |
Output is correct |
12 |
Correct |
4 ms |
680 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
14 |
Correct |
5 ms |
680 KB |
Output is correct |
15 |
Correct |
3 ms |
792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
4 ms |
804 KB |
Output is correct |
5 |
Correct |
3 ms |
792 KB |
Output is correct |
6 |
Correct |
4 ms |
680 KB |
Output is correct |
7 |
Correct |
3 ms |
632 KB |
Output is correct |
8 |
Correct |
4 ms |
680 KB |
Output is correct |
9 |
Correct |
3 ms |
712 KB |
Output is correct |
10 |
Correct |
4 ms |
632 KB |
Output is correct |
11 |
Correct |
3 ms |
704 KB |
Output is correct |
12 |
Correct |
4 ms |
680 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
14 |
Correct |
5 ms |
680 KB |
Output is correct |
15 |
Correct |
3 ms |
792 KB |
Output is correct |
16 |
Correct |
8 ms |
1272 KB |
Output is correct |
17 |
Correct |
14 ms |
2296 KB |
Output is correct |
18 |
Correct |
10 ms |
3652 KB |
Output is correct |
19 |
Correct |
32 ms |
4356 KB |
Output is correct |
20 |
Correct |
29 ms |
4344 KB |
Output is correct |
21 |
Correct |
30 ms |
4272 KB |
Output is correct |
22 |
Correct |
30 ms |
4344 KB |
Output is correct |
23 |
Correct |
26 ms |
4344 KB |
Output is correct |
24 |
Correct |
21 ms |
4352 KB |
Output is correct |
25 |
Correct |
25 ms |
4392 KB |
Output is correct |
26 |
Correct |
26 ms |
4392 KB |
Output is correct |
27 |
Correct |
26 ms |
4264 KB |
Output is correct |
28 |
Correct |
31 ms |
4372 KB |
Output is correct |
29 |
Correct |
24 ms |
4472 KB |
Output is correct |
30 |
Correct |
31 ms |
4344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
4 ms |
804 KB |
Output is correct |
5 |
Correct |
3 ms |
792 KB |
Output is correct |
6 |
Correct |
4 ms |
680 KB |
Output is correct |
7 |
Correct |
3 ms |
632 KB |
Output is correct |
8 |
Correct |
4 ms |
680 KB |
Output is correct |
9 |
Correct |
3 ms |
712 KB |
Output is correct |
10 |
Correct |
4 ms |
632 KB |
Output is correct |
11 |
Correct |
3 ms |
704 KB |
Output is correct |
12 |
Correct |
4 ms |
680 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
14 |
Correct |
5 ms |
680 KB |
Output is correct |
15 |
Correct |
3 ms |
792 KB |
Output is correct |
16 |
Correct |
8 ms |
1272 KB |
Output is correct |
17 |
Correct |
14 ms |
2296 KB |
Output is correct |
18 |
Correct |
10 ms |
3652 KB |
Output is correct |
19 |
Correct |
32 ms |
4356 KB |
Output is correct |
20 |
Correct |
29 ms |
4344 KB |
Output is correct |
21 |
Correct |
30 ms |
4272 KB |
Output is correct |
22 |
Correct |
30 ms |
4344 KB |
Output is correct |
23 |
Correct |
26 ms |
4344 KB |
Output is correct |
24 |
Correct |
21 ms |
4352 KB |
Output is correct |
25 |
Correct |
25 ms |
4392 KB |
Output is correct |
26 |
Correct |
26 ms |
4392 KB |
Output is correct |
27 |
Correct |
26 ms |
4264 KB |
Output is correct |
28 |
Correct |
31 ms |
4372 KB |
Output is correct |
29 |
Correct |
24 ms |
4472 KB |
Output is correct |
30 |
Correct |
31 ms |
4344 KB |
Output is correct |
31 |
Correct |
27 ms |
9152 KB |
Output is correct |
32 |
Correct |
95 ms |
12792 KB |
Output is correct |
33 |
Correct |
107 ms |
17932 KB |
Output is correct |
34 |
Correct |
120 ms |
20548 KB |
Output is correct |
35 |
Correct |
191 ms |
20552 KB |
Output is correct |
36 |
Correct |
223 ms |
20600 KB |
Output is correct |
37 |
Correct |
405 ms |
20472 KB |
Output is correct |
38 |
Correct |
125 ms |
20468 KB |
Output is correct |
39 |
Correct |
127 ms |
20472 KB |
Output is correct |
40 |
Correct |
126 ms |
20644 KB |
Output is correct |
41 |
Correct |
120 ms |
20472 KB |
Output is correct |
42 |
Correct |
235 ms |
20472 KB |
Output is correct |
43 |
Correct |
236 ms |
20600 KB |
Output is correct |
44 |
Correct |
123 ms |
20556 KB |
Output is correct |
45 |
Correct |
132 ms |
20520 KB |
Output is correct |
46 |
Correct |
154 ms |
20572 KB |
Output is correct |
47 |
Correct |
128 ms |
20520 KB |
Output is correct |
48 |
Correct |
120 ms |
20468 KB |
Output is correct |
49 |
Correct |
145 ms |
20596 KB |
Output is correct |
50 |
Correct |
134 ms |
20488 KB |
Output is correct |
51 |
Correct |
141 ms |
20600 KB |
Output is correct |
52 |
Correct |
163 ms |
20544 KB |
Output is correct |
53 |
Correct |
132 ms |
20544 KB |
Output is correct |
54 |
Correct |
124 ms |
20568 KB |
Output is correct |
55 |
Correct |
88 ms |
20684 KB |
Output is correct |
56 |
Correct |
123 ms |
20520 KB |
Output is correct |
57 |
Correct |
111 ms |
20600 KB |
Output is correct |
58 |
Correct |
178 ms |
20556 KB |
Output is correct |
59 |
Correct |
121 ms |
20552 KB |
Output is correct |
60 |
Correct |
116 ms |
20516 KB |
Output is correct |