#include "xylophone.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 5010;
static int a[N];
static int d1[N], d2[N], e[N];
void solve(int n)
{
Loop (i,0,n-1)
d1[i] = query(i+1, i+2);
Loop (i,0,n-2)
d2[i] = query(i+1, i+3);
e[0] = d1[0];
Loop (i,1,n-1) {
e[i] = d1[i];
if (e[i-1] < 0)
e[i] = -e[i];
if (d1[i-1] + d1[i] != d2[i-1])
e[i] = -e[i];
}
int mn = 0, mni = 0, cur = 0;
Loop (i,1,n) {
cur += e[i-1];
if (cur < mn) {
mni = i;
mn = cur;
}
}
cur = 0;
Loop (i,mni,n) {
a[i] = cur;
cur += e[i];
}
cur = 0;
LoopR (i,0,mni) {
cur -= e[i];
a[i] = cur;
}
int pos_n = 0;
while (a[pos_n] != n-1)
++pos_n;
if (mni > pos_n) {
Loop (i,0,n)
a[i] = n-1-a[i];
}
Loop (i,0,n)
answer(i+1, a[i]+1);
}
# |
결과 |
실행 시간 |
메모리 |
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 |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
316 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
304 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 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 |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
316 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
304 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
8 ms |
208 KB |
Output is correct |
18 |
Correct |
16 ms |
312 KB |
Output is correct |
19 |
Correct |
12 ms |
308 KB |
Output is correct |
20 |
Correct |
22 ms |
312 KB |
Output is correct |
21 |
Correct |
10 ms |
308 KB |
Output is correct |
22 |
Correct |
16 ms |
312 KB |
Output is correct |
23 |
Correct |
16 ms |
308 KB |
Output is correct |
24 |
Correct |
15 ms |
300 KB |
Output is correct |
25 |
Correct |
16 ms |
312 KB |
Output is correct |
26 |
Correct |
18 ms |
312 KB |
Output is correct |
27 |
Correct |
20 ms |
308 KB |
Output is correct |
28 |
Correct |
15 ms |
312 KB |
Output is correct |
29 |
Correct |
19 ms |
300 KB |
Output is correct |
30 |
Correct |
16 ms |
312 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 |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
316 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
304 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
8 ms |
208 KB |
Output is correct |
18 |
Correct |
16 ms |
312 KB |
Output is correct |
19 |
Correct |
12 ms |
308 KB |
Output is correct |
20 |
Correct |
22 ms |
312 KB |
Output is correct |
21 |
Correct |
10 ms |
308 KB |
Output is correct |
22 |
Correct |
16 ms |
312 KB |
Output is correct |
23 |
Correct |
16 ms |
308 KB |
Output is correct |
24 |
Correct |
15 ms |
300 KB |
Output is correct |
25 |
Correct |
16 ms |
312 KB |
Output is correct |
26 |
Correct |
18 ms |
312 KB |
Output is correct |
27 |
Correct |
20 ms |
308 KB |
Output is correct |
28 |
Correct |
15 ms |
312 KB |
Output is correct |
29 |
Correct |
19 ms |
300 KB |
Output is correct |
30 |
Correct |
16 ms |
312 KB |
Output is correct |
31 |
Correct |
34 ms |
312 KB |
Output is correct |
32 |
Correct |
53 ms |
308 KB |
Output is correct |
33 |
Correct |
68 ms |
300 KB |
Output is correct |
34 |
Correct |
101 ms |
292 KB |
Output is correct |
35 |
Correct |
86 ms |
304 KB |
Output is correct |
36 |
Correct |
94 ms |
328 KB |
Output is correct |
37 |
Correct |
106 ms |
488 KB |
Output is correct |
38 |
Correct |
92 ms |
312 KB |
Output is correct |
39 |
Correct |
94 ms |
316 KB |
Output is correct |
40 |
Correct |
56 ms |
308 KB |
Output is correct |
41 |
Correct |
72 ms |
324 KB |
Output is correct |
42 |
Correct |
105 ms |
304 KB |
Output is correct |
43 |
Correct |
96 ms |
328 KB |
Output is correct |
44 |
Correct |
51 ms |
424 KB |
Output is correct |
45 |
Correct |
75 ms |
312 KB |
Output is correct |
46 |
Correct |
87 ms |
336 KB |
Output is correct |
47 |
Correct |
81 ms |
420 KB |
Output is correct |
48 |
Correct |
85 ms |
428 KB |
Output is correct |
49 |
Correct |
80 ms |
332 KB |
Output is correct |
50 |
Correct |
89 ms |
312 KB |
Output is correct |
51 |
Correct |
84 ms |
320 KB |
Output is correct |
52 |
Correct |
84 ms |
328 KB |
Output is correct |
53 |
Correct |
80 ms |
308 KB |
Output is correct |
54 |
Correct |
79 ms |
436 KB |
Output is correct |
55 |
Correct |
75 ms |
336 KB |
Output is correct |
56 |
Correct |
87 ms |
316 KB |
Output is correct |
57 |
Correct |
41 ms |
316 KB |
Output is correct |
58 |
Correct |
50 ms |
296 KB |
Output is correct |
59 |
Correct |
70 ms |
336 KB |
Output is correct |
60 |
Correct |
87 ms |
316 KB |
Output is correct |