#include "xylophone.h"
#include<bits/stdc++.h>
using namespace std;
const int Nmax = 5005;
static int A[Nmax], B[Nmax], x[Nmax];
void solve(int N)
{
int i;
for(i=1; i<=N-1; ++i) A[i] = query(i, i+1);
for(i=1; i<=N-2; ++i) B[i] = query(i, i+2);
x[1] = 0; x[2] = A[1];
for(i=3; i<=N; ++i)
if(x[i-2] < x[i-1])
{
if(B[i-2] == A[i-2]) /// middle value
x[i] = x[i-1] - A[i-1];
else if(A[i-1] == B[i-2]) /// smallest value
x[i] = x[i-1] - A[i-1];
else x[i] = x[i-1] + A[i-1]; /// greatest value
}
else
{
if(B[i-2] == A[i-2]) /// middle
x[i] = x[i-1] + A[i-1];
else if(A[i-1] == B[i-2]) /// greatest
x[i] = x[i-1] + A[i-1];
else x[i] = x[i-1] - A[i-1];
}
int Min = 0;
for(i=1; i<=N; ++i) Min = min(Min, x[i]);
for(i=1; i<=N; ++i) x[i] -= Min - 1;
int id1 = -1, idn = -1;
for(i=1; i<=N; ++i)
if(x[i] == 1) id1 = i;
else if(x[i] == N) idn = i;
assert(id1 != -1); assert(idn != -1);
if(id1 > idn)
for(i=1; i<=N; ++i) x[i] = N + 1 - x[i];
for(i=1; i<=N; ++i) answer(i, x[i]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
248 KB |
Output is correct |
4 |
Correct |
4 ms |
248 KB |
Output is correct |
5 |
Correct |
2 ms |
312 KB |
Output is correct |
6 |
Correct |
3 ms |
248 KB |
Output is correct |
7 |
Correct |
4 ms |
248 KB |
Output is correct |
8 |
Correct |
4 ms |
248 KB |
Output is correct |
9 |
Correct |
3 ms |
248 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
252 KB |
Output is correct |
12 |
Correct |
3 ms |
248 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
248 KB |
Output is correct |
15 |
Correct |
3 ms |
248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
248 KB |
Output is correct |
4 |
Correct |
4 ms |
248 KB |
Output is correct |
5 |
Correct |
2 ms |
312 KB |
Output is correct |
6 |
Correct |
3 ms |
248 KB |
Output is correct |
7 |
Correct |
4 ms |
248 KB |
Output is correct |
8 |
Correct |
4 ms |
248 KB |
Output is correct |
9 |
Correct |
3 ms |
248 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
252 KB |
Output is correct |
12 |
Correct |
3 ms |
248 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
248 KB |
Output is correct |
15 |
Correct |
3 ms |
248 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
10 ms |
248 KB |
Output is correct |
18 |
Correct |
7 ms |
400 KB |
Output is correct |
19 |
Correct |
19 ms |
248 KB |
Output is correct |
20 |
Correct |
19 ms |
376 KB |
Output is correct |
21 |
Correct |
20 ms |
380 KB |
Output is correct |
22 |
Correct |
8 ms |
316 KB |
Output is correct |
23 |
Correct |
18 ms |
376 KB |
Output is correct |
24 |
Correct |
17 ms |
376 KB |
Output is correct |
25 |
Correct |
17 ms |
248 KB |
Output is correct |
26 |
Correct |
20 ms |
376 KB |
Output is correct |
27 |
Correct |
19 ms |
424 KB |
Output is correct |
28 |
Correct |
22 ms |
328 KB |
Output is correct |
29 |
Correct |
18 ms |
376 KB |
Output is correct |
30 |
Correct |
19 ms |
248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
248 KB |
Output is correct |
4 |
Correct |
4 ms |
248 KB |
Output is correct |
5 |
Correct |
2 ms |
312 KB |
Output is correct |
6 |
Correct |
3 ms |
248 KB |
Output is correct |
7 |
Correct |
4 ms |
248 KB |
Output is correct |
8 |
Correct |
4 ms |
248 KB |
Output is correct |
9 |
Correct |
3 ms |
248 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
252 KB |
Output is correct |
12 |
Correct |
3 ms |
248 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
248 KB |
Output is correct |
15 |
Correct |
3 ms |
248 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
10 ms |
248 KB |
Output is correct |
18 |
Correct |
7 ms |
400 KB |
Output is correct |
19 |
Correct |
19 ms |
248 KB |
Output is correct |
20 |
Correct |
19 ms |
376 KB |
Output is correct |
21 |
Correct |
20 ms |
380 KB |
Output is correct |
22 |
Correct |
8 ms |
316 KB |
Output is correct |
23 |
Correct |
18 ms |
376 KB |
Output is correct |
24 |
Correct |
17 ms |
376 KB |
Output is correct |
25 |
Correct |
17 ms |
248 KB |
Output is correct |
26 |
Correct |
20 ms |
376 KB |
Output is correct |
27 |
Correct |
19 ms |
424 KB |
Output is correct |
28 |
Correct |
22 ms |
328 KB |
Output is correct |
29 |
Correct |
18 ms |
376 KB |
Output is correct |
30 |
Correct |
19 ms |
248 KB |
Output is correct |
31 |
Correct |
40 ms |
248 KB |
Output is correct |
32 |
Correct |
59 ms |
344 KB |
Output is correct |
33 |
Correct |
80 ms |
380 KB |
Output is correct |
34 |
Correct |
84 ms |
376 KB |
Output is correct |
35 |
Correct |
95 ms |
340 KB |
Output is correct |
36 |
Correct |
57 ms |
376 KB |
Output is correct |
37 |
Correct |
103 ms |
336 KB |
Output is correct |
38 |
Correct |
84 ms |
436 KB |
Output is correct |
39 |
Correct |
81 ms |
332 KB |
Output is correct |
40 |
Correct |
80 ms |
456 KB |
Output is correct |
41 |
Correct |
60 ms |
460 KB |
Output is correct |
42 |
Correct |
96 ms |
376 KB |
Output is correct |
43 |
Correct |
54 ms |
456 KB |
Output is correct |
44 |
Correct |
87 ms |
356 KB |
Output is correct |
45 |
Correct |
96 ms |
372 KB |
Output is correct |
46 |
Correct |
57 ms |
404 KB |
Output is correct |
47 |
Correct |
34 ms |
340 KB |
Output is correct |
48 |
Correct |
50 ms |
400 KB |
Output is correct |
49 |
Correct |
43 ms |
424 KB |
Output is correct |
50 |
Correct |
104 ms |
376 KB |
Output is correct |
51 |
Correct |
93 ms |
376 KB |
Output is correct |
52 |
Correct |
103 ms |
376 KB |
Output is correct |
53 |
Correct |
33 ms |
404 KB |
Output is correct |
54 |
Correct |
55 ms |
376 KB |
Output is correct |
55 |
Correct |
110 ms |
248 KB |
Output is correct |
56 |
Correct |
38 ms |
344 KB |
Output is correct |
57 |
Correct |
82 ms |
376 KB |
Output is correct |
58 |
Correct |
33 ms |
376 KB |
Output is correct |
59 |
Correct |
55 ms |
424 KB |
Output is correct |
60 |
Correct |
101 ms |
376 KB |
Output is correct |