#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
void solve(int n)
{
vector<vector<int>> q(n + 1, vector<int>(n + 1, INT_MAX));
for (int i = 2; i <= n; i++)
q[i - 1][i] = query(i - 1, i);
for (int i = 3; i <= n; i++)
q[i - 2][i] = query(i - 2, i);
vector<int> trend(n + 1);
trend[2] = 1;
for (int i = 3; i <= n; i++)
{
if (q[i - 2][i - 1] + q[i - 1][i] == q[i - 2][i])
trend[i] = trend[i - 1];
else
trend[i] = - trend[i - 1];
}
vector<int> v(n + 1);
int iMin = 1, iMax = 1;
v[1] = 0;
for (int i = 2; i <= n; i++)
{
v[i] = v[i - 1] + trend[i] * q[i - 1][i];
if (v[i] < v[iMin]) iMin = i;
if (v[i] > v[iMax]) iMax = i;
}
int d = 1 - v[iMin];
for (int i = 1; i <= n; i++)
v[i] += d;
if (iMin > iMax)
for (int i = 1; i <= n; i++)
v[i] = n + 1 - v[i];
for (int i = 1; i <= n; i++)
answer(i, v[i]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
2 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
2 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
3 ms |
464 KB |
Output is correct |
17 |
Correct |
6 ms |
1104 KB |
Output is correct |
18 |
Correct |
15 ms |
2896 KB |
Output is correct |
19 |
Correct |
15 ms |
4228 KB |
Output is correct |
20 |
Correct |
11 ms |
4176 KB |
Output is correct |
21 |
Correct |
17 ms |
4176 KB |
Output is correct |
22 |
Correct |
14 ms |
4176 KB |
Output is correct |
23 |
Correct |
19 ms |
4244 KB |
Output is correct |
24 |
Correct |
19 ms |
4240 KB |
Output is correct |
25 |
Correct |
8 ms |
4252 KB |
Output is correct |
26 |
Correct |
14 ms |
4256 KB |
Output is correct |
27 |
Correct |
19 ms |
4236 KB |
Output is correct |
28 |
Correct |
19 ms |
4240 KB |
Output is correct |
29 |
Correct |
13 ms |
4176 KB |
Output is correct |
30 |
Correct |
18 ms |
4176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
2 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
3 ms |
464 KB |
Output is correct |
17 |
Correct |
6 ms |
1104 KB |
Output is correct |
18 |
Correct |
15 ms |
2896 KB |
Output is correct |
19 |
Correct |
15 ms |
4228 KB |
Output is correct |
20 |
Correct |
11 ms |
4176 KB |
Output is correct |
21 |
Correct |
17 ms |
4176 KB |
Output is correct |
22 |
Correct |
14 ms |
4176 KB |
Output is correct |
23 |
Correct |
19 ms |
4244 KB |
Output is correct |
24 |
Correct |
19 ms |
4240 KB |
Output is correct |
25 |
Correct |
8 ms |
4252 KB |
Output is correct |
26 |
Correct |
14 ms |
4256 KB |
Output is correct |
27 |
Correct |
19 ms |
4236 KB |
Output is correct |
28 |
Correct |
19 ms |
4240 KB |
Output is correct |
29 |
Correct |
13 ms |
4176 KB |
Output is correct |
30 |
Correct |
18 ms |
4176 KB |
Output is correct |
31 |
Correct |
21 ms |
18724 KB |
Output is correct |
32 |
Correct |
62 ms |
37724 KB |
Output is correct |
33 |
Correct |
94 ms |
74728 KB |
Output is correct |
34 |
Correct |
100 ms |
98276 KB |
Output is correct |
35 |
Correct |
117 ms |
98420 KB |
Output is correct |
36 |
Correct |
118 ms |
98340 KB |
Output is correct |
37 |
Correct |
116 ms |
98376 KB |
Output is correct |
38 |
Correct |
107 ms |
98408 KB |
Output is correct |
39 |
Correct |
99 ms |
98340 KB |
Output is correct |
40 |
Correct |
97 ms |
98336 KB |
Output is correct |
41 |
Correct |
99 ms |
98376 KB |
Output is correct |
42 |
Correct |
112 ms |
98364 KB |
Output is correct |
43 |
Correct |
79 ms |
98360 KB |
Output is correct |
44 |
Correct |
121 ms |
98356 KB |
Output is correct |
45 |
Correct |
115 ms |
98360 KB |
Output is correct |
46 |
Correct |
108 ms |
98380 KB |
Output is correct |
47 |
Correct |
111 ms |
98360 KB |
Output is correct |
48 |
Correct |
97 ms |
98404 KB |
Output is correct |
49 |
Correct |
118 ms |
98376 KB |
Output is correct |
50 |
Correct |
115 ms |
98380 KB |
Output is correct |
51 |
Correct |
91 ms |
98376 KB |
Output is correct |
52 |
Correct |
98 ms |
98360 KB |
Output is correct |
53 |
Correct |
81 ms |
98364 KB |
Output is correct |
54 |
Correct |
112 ms |
98356 KB |
Output is correct |
55 |
Correct |
73 ms |
98356 KB |
Output is correct |
56 |
Correct |
121 ms |
98356 KB |
Output is correct |
57 |
Correct |
99 ms |
98376 KB |
Output is correct |
58 |
Correct |
115 ms |
98364 KB |
Output is correct |
59 |
Correct |
105 ms |
98360 KB |
Output is correct |
60 |
Correct |
121 ms |
98368 KB |
Output is correct |