#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
void solve(int n)
{
vector<int> d(n + 1), c(n + 1, 0);
for (int i = 2; i <= n; i++) d[i] = query(i - 1, i);
for (int i = 3; i <= n; i++)
{
c[i] = c[i - 1];
if (query(i - 2, i) < d[i - 1] + d[i]) c[i] ^= 1;
}
for (int i = 2; i <= n; i++)
{
if (c[i]) d[i] = -d[i];
}
array<int, 2> b = {-1, -1};
for (int i = 1; i <= n; i++)
{
int s = 0;
for (int j = i + 1; j <= n; j++)
{
s += d[j];
if (abs(s) == n - 1)
{
b = {i, s};
break;
}
}
}
if (b[1] < 0)
{
for (int i = 2; i <= n; i++) d[i] = -d[i];
}
int a[n + 1];
a[b[0]] = 1;
for (int i = b[0] + 1; i <= n; i++) a[i] = a[i - 1] + d[i];
for (int i = b[0] - 1; i >= 1; i--) a[i] = a[i + 1] - d[i + 1];
for (int i = 1; i <= n; i++)
{
answer(i, a[i]);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
500 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
500 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
2 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
4 ms |
440 KB |
Output is correct |
18 |
Correct |
7 ms |
444 KB |
Output is correct |
19 |
Correct |
10 ms |
344 KB |
Output is correct |
20 |
Correct |
8 ms |
436 KB |
Output is correct |
21 |
Correct |
10 ms |
440 KB |
Output is correct |
22 |
Correct |
8 ms |
596 KB |
Output is correct |
23 |
Correct |
8 ms |
444 KB |
Output is correct |
24 |
Correct |
8 ms |
448 KB |
Output is correct |
25 |
Correct |
9 ms |
444 KB |
Output is correct |
26 |
Correct |
8 ms |
444 KB |
Output is correct |
27 |
Correct |
12 ms |
440 KB |
Output is correct |
28 |
Correct |
8 ms |
440 KB |
Output is correct |
29 |
Correct |
9 ms |
448 KB |
Output is correct |
30 |
Correct |
9 ms |
440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
500 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
2 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
4 ms |
440 KB |
Output is correct |
18 |
Correct |
7 ms |
444 KB |
Output is correct |
19 |
Correct |
10 ms |
344 KB |
Output is correct |
20 |
Correct |
8 ms |
436 KB |
Output is correct |
21 |
Correct |
10 ms |
440 KB |
Output is correct |
22 |
Correct |
8 ms |
596 KB |
Output is correct |
23 |
Correct |
8 ms |
444 KB |
Output is correct |
24 |
Correct |
8 ms |
448 KB |
Output is correct |
25 |
Correct |
9 ms |
444 KB |
Output is correct |
26 |
Correct |
8 ms |
444 KB |
Output is correct |
27 |
Correct |
12 ms |
440 KB |
Output is correct |
28 |
Correct |
8 ms |
440 KB |
Output is correct |
29 |
Correct |
9 ms |
448 KB |
Output is correct |
30 |
Correct |
9 ms |
440 KB |
Output is correct |
31 |
Correct |
22 ms |
448 KB |
Output is correct |
32 |
Correct |
25 ms |
444 KB |
Output is correct |
33 |
Correct |
48 ms |
464 KB |
Output is correct |
34 |
Correct |
57 ms |
456 KB |
Output is correct |
35 |
Correct |
58 ms |
516 KB |
Output is correct |
36 |
Correct |
47 ms |
452 KB |
Output is correct |
37 |
Correct |
59 ms |
524 KB |
Output is correct |
38 |
Correct |
55 ms |
448 KB |
Output is correct |
39 |
Correct |
65 ms |
464 KB |
Output is correct |
40 |
Correct |
54 ms |
472 KB |
Output is correct |
41 |
Correct |
65 ms |
452 KB |
Output is correct |
42 |
Correct |
57 ms |
452 KB |
Output is correct |
43 |
Correct |
52 ms |
500 KB |
Output is correct |
44 |
Correct |
67 ms |
540 KB |
Output is correct |
45 |
Correct |
53 ms |
472 KB |
Output is correct |
46 |
Correct |
73 ms |
468 KB |
Output is correct |
47 |
Correct |
54 ms |
468 KB |
Output is correct |
48 |
Correct |
54 ms |
472 KB |
Output is correct |
49 |
Correct |
56 ms |
464 KB |
Output is correct |
50 |
Correct |
63 ms |
464 KB |
Output is correct |
51 |
Correct |
59 ms |
448 KB |
Output is correct |
52 |
Correct |
66 ms |
452 KB |
Output is correct |
53 |
Correct |
61 ms |
452 KB |
Output is correct |
54 |
Correct |
47 ms |
448 KB |
Output is correct |
55 |
Correct |
57 ms |
464 KB |
Output is correct |
56 |
Correct |
68 ms |
488 KB |
Output is correct |
57 |
Correct |
57 ms |
512 KB |
Output is correct |
58 |
Correct |
67 ms |
468 KB |
Output is correct |
59 |
Correct |
57 ms |
472 KB |
Output is correct |
60 |
Correct |
52 ms |
452 KB |
Output is correct |