#include "xylophone.h"
#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mid (l+r)/2
#define endl '\n'
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 5010
int s2[MAXN], s3[MAXN], A[MAXN];
void solve(int N) {
for(int i = 2; i <= N; i++) s2[i] = query(i-1, i);
for(int i = 3; i <= N; i++) s3[i] = query(i-2, i);
A[1] = 0; A[2] = s2[2];
for(int i = 3; i <= N; i++) {
if(A[i-2] < A[i-1]) {
if(s2[i]+s2[i-1] == s3[i]) A[i] = A[i-1] + s2[i];
else A[i] = A[i-1] - s2[i];
} else if(A[i-2] > A[i-1]) {
if(s2[i]+s2[i-1] == s3[i]) A[i] = A[i-1] - s2[i];
else A[i] = A[i-1] + s2[i];
}
}
int minn = INF, idx1 = 1, idxN = 1;
for(int i = 1; i <= N; i++) minn = min(minn, A[i]);
for(int i = 1; i <= N; i++) {
A[i] += (1-minn);
if(A[i] == 1) idx1 = i;
if(A[i] == N) idxN = i;
}
for(int i = 1; i <= N; i++) answer(i, (idx1 < idxN ? A[i]:N+1-A[i]));
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
248 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
4 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
248 KB |
Output is correct |
9 |
Correct |
3 ms |
316 KB |
Output is correct |
10 |
Correct |
3 ms |
248 KB |
Output is correct |
11 |
Correct |
3 ms |
400 KB |
Output is correct |
12 |
Correct |
5 ms |
404 KB |
Output is correct |
13 |
Correct |
3 ms |
396 KB |
Output is correct |
14 |
Correct |
4 ms |
376 KB |
Output is correct |
15 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
248 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
4 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
248 KB |
Output is correct |
9 |
Correct |
3 ms |
316 KB |
Output is correct |
10 |
Correct |
3 ms |
248 KB |
Output is correct |
11 |
Correct |
3 ms |
400 KB |
Output is correct |
12 |
Correct |
5 ms |
404 KB |
Output is correct |
13 |
Correct |
3 ms |
396 KB |
Output is correct |
14 |
Correct |
4 ms |
376 KB |
Output is correct |
15 |
Correct |
4 ms |
376 KB |
Output is correct |
16 |
Correct |
7 ms |
320 KB |
Output is correct |
17 |
Correct |
15 ms |
412 KB |
Output is correct |
18 |
Correct |
24 ms |
324 KB |
Output is correct |
19 |
Correct |
21 ms |
376 KB |
Output is correct |
20 |
Correct |
22 ms |
248 KB |
Output is correct |
21 |
Correct |
22 ms |
248 KB |
Output is correct |
22 |
Correct |
25 ms |
248 KB |
Output is correct |
23 |
Correct |
27 ms |
376 KB |
Output is correct |
24 |
Correct |
27 ms |
376 KB |
Output is correct |
25 |
Correct |
27 ms |
248 KB |
Output is correct |
26 |
Correct |
26 ms |
376 KB |
Output is correct |
27 |
Correct |
27 ms |
424 KB |
Output is correct |
28 |
Correct |
14 ms |
504 KB |
Output is correct |
29 |
Correct |
27 ms |
248 KB |
Output is correct |
30 |
Correct |
13 ms |
400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
248 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
4 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
248 KB |
Output is correct |
9 |
Correct |
3 ms |
316 KB |
Output is correct |
10 |
Correct |
3 ms |
248 KB |
Output is correct |
11 |
Correct |
3 ms |
400 KB |
Output is correct |
12 |
Correct |
5 ms |
404 KB |
Output is correct |
13 |
Correct |
3 ms |
396 KB |
Output is correct |
14 |
Correct |
4 ms |
376 KB |
Output is correct |
15 |
Correct |
4 ms |
376 KB |
Output is correct |
16 |
Correct |
7 ms |
320 KB |
Output is correct |
17 |
Correct |
15 ms |
412 KB |
Output is correct |
18 |
Correct |
24 ms |
324 KB |
Output is correct |
19 |
Correct |
21 ms |
376 KB |
Output is correct |
20 |
Correct |
22 ms |
248 KB |
Output is correct |
21 |
Correct |
22 ms |
248 KB |
Output is correct |
22 |
Correct |
25 ms |
248 KB |
Output is correct |
23 |
Correct |
27 ms |
376 KB |
Output is correct |
24 |
Correct |
27 ms |
376 KB |
Output is correct |
25 |
Correct |
27 ms |
248 KB |
Output is correct |
26 |
Correct |
26 ms |
376 KB |
Output is correct |
27 |
Correct |
27 ms |
424 KB |
Output is correct |
28 |
Correct |
14 ms |
504 KB |
Output is correct |
29 |
Correct |
27 ms |
248 KB |
Output is correct |
30 |
Correct |
13 ms |
400 KB |
Output is correct |
31 |
Correct |
46 ms |
324 KB |
Output is correct |
32 |
Correct |
60 ms |
376 KB |
Output is correct |
33 |
Correct |
87 ms |
460 KB |
Output is correct |
34 |
Correct |
103 ms |
404 KB |
Output is correct |
35 |
Correct |
99 ms |
376 KB |
Output is correct |
36 |
Correct |
100 ms |
376 KB |
Output is correct |
37 |
Correct |
102 ms |
404 KB |
Output is correct |
38 |
Correct |
53 ms |
360 KB |
Output is correct |
39 |
Correct |
64 ms |
528 KB |
Output is correct |
40 |
Correct |
100 ms |
444 KB |
Output is correct |
41 |
Correct |
114 ms |
384 KB |
Output is correct |
42 |
Correct |
94 ms |
468 KB |
Output is correct |
43 |
Correct |
105 ms |
336 KB |
Output is correct |
44 |
Correct |
107 ms |
336 KB |
Output is correct |
45 |
Correct |
103 ms |
332 KB |
Output is correct |
46 |
Correct |
60 ms |
452 KB |
Output is correct |
47 |
Correct |
106 ms |
376 KB |
Output is correct |
48 |
Correct |
109 ms |
376 KB |
Output is correct |
49 |
Correct |
84 ms |
424 KB |
Output is correct |
50 |
Correct |
53 ms |
356 KB |
Output is correct |
51 |
Correct |
93 ms |
508 KB |
Output is correct |
52 |
Correct |
107 ms |
380 KB |
Output is correct |
53 |
Correct |
89 ms |
384 KB |
Output is correct |
54 |
Correct |
70 ms |
332 KB |
Output is correct |
55 |
Correct |
103 ms |
380 KB |
Output is correct |
56 |
Correct |
105 ms |
376 KB |
Output is correct |
57 |
Correct |
104 ms |
408 KB |
Output is correct |
58 |
Correct |
75 ms |
528 KB |
Output is correct |
59 |
Correct |
98 ms |
336 KB |
Output is correct |
60 |
Correct |
75 ms |
360 KB |
Output is correct |