#include "xylophone.h"
#include <algorithm>
int a[5005], c[5005], d[5005];
void solve(int n)
{
for(int i = 1; i < n; i++)
{
c[i] = query(i, i + 1);
}
for(int i = 1; i + 1 < n; i++)
{
d[i] = query(i, i + 2);
}
a[1] = 0;
a[2] = c[1];
for(int i = 3; i <= n; i++)
{
int upper = a[i - 1] + c[i - 1];
int lower = a[i - 1] - c[i - 1];
if(d[i - 2] == std::max({a[i - 2], a[i - 1], upper}) - std::min({a[i - 2], a[i - 1], upper}))
{
a[i] = upper;
}
else
{
a[i] = lower;
}
}
int idmin = 1, idmax = 1;
for(int i = 1; i <= n; i++)
{
if(a[idmin] > a[i])
{
idmin = i;
}
if(a[idmax] < a[i])
{
idmax = i;
}
}
if(idmin > idmax)
{
for(int i = 1; i <= n; i++)
{
a[i] = -a[i];
}
}
int value = 1 - a[std::min(idmin, idmax)];
for(int i = 1; i <= n; i++)
{
a[i] += value;
answer(i, a[i]);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
4 ms |
364 KB |
Output is correct |
17 |
Correct |
9 ms |
364 KB |
Output is correct |
18 |
Correct |
14 ms |
364 KB |
Output is correct |
19 |
Correct |
18 ms |
364 KB |
Output is correct |
20 |
Correct |
19 ms |
364 KB |
Output is correct |
21 |
Correct |
20 ms |
364 KB |
Output is correct |
22 |
Correct |
18 ms |
364 KB |
Output is correct |
23 |
Correct |
18 ms |
364 KB |
Output is correct |
24 |
Correct |
20 ms |
364 KB |
Output is correct |
25 |
Correct |
24 ms |
364 KB |
Output is correct |
26 |
Correct |
11 ms |
496 KB |
Output is correct |
27 |
Correct |
19 ms |
512 KB |
Output is correct |
28 |
Correct |
18 ms |
364 KB |
Output is correct |
29 |
Correct |
20 ms |
364 KB |
Output is correct |
30 |
Correct |
16 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
4 ms |
364 KB |
Output is correct |
17 |
Correct |
9 ms |
364 KB |
Output is correct |
18 |
Correct |
14 ms |
364 KB |
Output is correct |
19 |
Correct |
18 ms |
364 KB |
Output is correct |
20 |
Correct |
19 ms |
364 KB |
Output is correct |
21 |
Correct |
20 ms |
364 KB |
Output is correct |
22 |
Correct |
18 ms |
364 KB |
Output is correct |
23 |
Correct |
18 ms |
364 KB |
Output is correct |
24 |
Correct |
20 ms |
364 KB |
Output is correct |
25 |
Correct |
24 ms |
364 KB |
Output is correct |
26 |
Correct |
11 ms |
496 KB |
Output is correct |
27 |
Correct |
19 ms |
512 KB |
Output is correct |
28 |
Correct |
18 ms |
364 KB |
Output is correct |
29 |
Correct |
20 ms |
364 KB |
Output is correct |
30 |
Correct |
16 ms |
364 KB |
Output is correct |
31 |
Correct |
41 ms |
384 KB |
Output is correct |
32 |
Correct |
65 ms |
496 KB |
Output is correct |
33 |
Correct |
94 ms |
372 KB |
Output is correct |
34 |
Correct |
94 ms |
364 KB |
Output is correct |
35 |
Correct |
114 ms |
364 KB |
Output is correct |
36 |
Correct |
86 ms |
492 KB |
Output is correct |
37 |
Correct |
118 ms |
504 KB |
Output is correct |
38 |
Correct |
74 ms |
492 KB |
Output is correct |
39 |
Correct |
115 ms |
404 KB |
Output is correct |
40 |
Correct |
86 ms |
364 KB |
Output is correct |
41 |
Correct |
99 ms |
512 KB |
Output is correct |
42 |
Correct |
93 ms |
364 KB |
Output is correct |
43 |
Correct |
110 ms |
516 KB |
Output is correct |
44 |
Correct |
81 ms |
368 KB |
Output is correct |
45 |
Correct |
96 ms |
504 KB |
Output is correct |
46 |
Correct |
95 ms |
364 KB |
Output is correct |
47 |
Correct |
77 ms |
364 KB |
Output is correct |
48 |
Correct |
94 ms |
364 KB |
Output is correct |
49 |
Correct |
121 ms |
492 KB |
Output is correct |
50 |
Correct |
76 ms |
492 KB |
Output is correct |
51 |
Correct |
93 ms |
624 KB |
Output is correct |
52 |
Correct |
88 ms |
364 KB |
Output is correct |
53 |
Correct |
106 ms |
620 KB |
Output is correct |
54 |
Correct |
106 ms |
492 KB |
Output is correct |
55 |
Correct |
87 ms |
364 KB |
Output is correct |
56 |
Correct |
66 ms |
492 KB |
Output is correct |
57 |
Correct |
85 ms |
524 KB |
Output is correct |
58 |
Correct |
117 ms |
364 KB |
Output is correct |
59 |
Correct |
56 ms |
492 KB |
Output is correct |
60 |
Correct |
96 ms |
492 KB |
Output is correct |