#include <bits/stdc++.h>
#ifndef safar
#include "xylophone.h"
#endif
using namespace std;
const int N = 5e3 + 10;
#ifdef safar
int query(int s, int t);
void answer(int i, int ai);
#endif
int d1[N], d2[N], c[N], ps[N];
void solve(int n){
for(int i = 1; i + 1 <= n; i++) d1[i] = query(i, i + 1);
for(int i = 1; i + 2 <= n; i++) d2[i] = query(i, i + 2);
c[1] = 1;
for(int i = 2; i + 1 <= n; i++) c[i] = (d1[i - 1] + d1[i] == d2[i - 1] ? 1 : -1) * c[i - 1];
ps[1] = 0;
for(int i = 2; i <= n; i++) ps[i] = ps[i - 1] + c[i - 1] * d1[i - 1];
int mn = *min_element(ps + 1, ps + 1 + n);
for(int i = 1; i <= n; i++) ps[i] += 1 - mn;
if(min_element(ps + 1, ps + 1 + n)-ps > max_element(ps + 1, ps + 1 + n)-ps){
for(int i = 1; i <= n; i++) ps[i] = n + 1 - ps[i];
}
for(int i = 1; i <= n; i++) answer(i, ps[i]);
return ;
}
#ifdef safar
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
return 0;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
256 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
6 ms |
384 KB |
Output is correct |
9 |
Correct |
7 ms |
384 KB |
Output is correct |
10 |
Correct |
7 ms |
384 KB |
Output is correct |
11 |
Correct |
7 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
384 KB |
Output is correct |
13 |
Correct |
7 ms |
384 KB |
Output is correct |
14 |
Correct |
7 ms |
384 KB |
Output is correct |
15 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
256 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
6 ms |
384 KB |
Output is correct |
9 |
Correct |
7 ms |
384 KB |
Output is correct |
10 |
Correct |
7 ms |
384 KB |
Output is correct |
11 |
Correct |
7 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
384 KB |
Output is correct |
13 |
Correct |
7 ms |
384 KB |
Output is correct |
14 |
Correct |
7 ms |
384 KB |
Output is correct |
15 |
Correct |
6 ms |
384 KB |
Output is correct |
16 |
Correct |
9 ms |
384 KB |
Output is correct |
17 |
Correct |
16 ms |
384 KB |
Output is correct |
18 |
Correct |
20 ms |
384 KB |
Output is correct |
19 |
Correct |
23 ms |
384 KB |
Output is correct |
20 |
Correct |
25 ms |
384 KB |
Output is correct |
21 |
Correct |
28 ms |
376 KB |
Output is correct |
22 |
Correct |
22 ms |
288 KB |
Output is correct |
23 |
Correct |
18 ms |
384 KB |
Output is correct |
24 |
Correct |
27 ms |
372 KB |
Output is correct |
25 |
Correct |
23 ms |
384 KB |
Output is correct |
26 |
Correct |
28 ms |
376 KB |
Output is correct |
27 |
Correct |
23 ms |
384 KB |
Output is correct |
28 |
Correct |
25 ms |
380 KB |
Output is correct |
29 |
Correct |
21 ms |
512 KB |
Output is correct |
30 |
Correct |
29 ms |
288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
256 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
6 ms |
384 KB |
Output is correct |
9 |
Correct |
7 ms |
384 KB |
Output is correct |
10 |
Correct |
7 ms |
384 KB |
Output is correct |
11 |
Correct |
7 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
384 KB |
Output is correct |
13 |
Correct |
7 ms |
384 KB |
Output is correct |
14 |
Correct |
7 ms |
384 KB |
Output is correct |
15 |
Correct |
6 ms |
384 KB |
Output is correct |
16 |
Correct |
9 ms |
384 KB |
Output is correct |
17 |
Correct |
16 ms |
384 KB |
Output is correct |
18 |
Correct |
20 ms |
384 KB |
Output is correct |
19 |
Correct |
23 ms |
384 KB |
Output is correct |
20 |
Correct |
25 ms |
384 KB |
Output is correct |
21 |
Correct |
28 ms |
376 KB |
Output is correct |
22 |
Correct |
22 ms |
288 KB |
Output is correct |
23 |
Correct |
18 ms |
384 KB |
Output is correct |
24 |
Correct |
27 ms |
372 KB |
Output is correct |
25 |
Correct |
23 ms |
384 KB |
Output is correct |
26 |
Correct |
28 ms |
376 KB |
Output is correct |
27 |
Correct |
23 ms |
384 KB |
Output is correct |
28 |
Correct |
25 ms |
380 KB |
Output is correct |
29 |
Correct |
21 ms |
512 KB |
Output is correct |
30 |
Correct |
29 ms |
288 KB |
Output is correct |
31 |
Correct |
58 ms |
376 KB |
Output is correct |
32 |
Correct |
81 ms |
384 KB |
Output is correct |
33 |
Correct |
109 ms |
384 KB |
Output is correct |
34 |
Correct |
113 ms |
376 KB |
Output is correct |
35 |
Correct |
111 ms |
376 KB |
Output is correct |
36 |
Correct |
116 ms |
504 KB |
Output is correct |
37 |
Correct |
96 ms |
384 KB |
Output is correct |
38 |
Correct |
115 ms |
504 KB |
Output is correct |
39 |
Correct |
112 ms |
384 KB |
Output is correct |
40 |
Correct |
88 ms |
376 KB |
Output is correct |
41 |
Correct |
89 ms |
400 KB |
Output is correct |
42 |
Correct |
89 ms |
516 KB |
Output is correct |
43 |
Correct |
90 ms |
384 KB |
Output is correct |
44 |
Correct |
52 ms |
620 KB |
Output is correct |
45 |
Correct |
113 ms |
508 KB |
Output is correct |
46 |
Correct |
96 ms |
376 KB |
Output is correct |
47 |
Correct |
93 ms |
384 KB |
Output is correct |
48 |
Correct |
97 ms |
516 KB |
Output is correct |
49 |
Correct |
111 ms |
384 KB |
Output is correct |
50 |
Correct |
115 ms |
384 KB |
Output is correct |
51 |
Correct |
113 ms |
604 KB |
Output is correct |
52 |
Correct |
90 ms |
384 KB |
Output is correct |
53 |
Correct |
78 ms |
372 KB |
Output is correct |
54 |
Correct |
83 ms |
380 KB |
Output is correct |
55 |
Correct |
92 ms |
376 KB |
Output is correct |
56 |
Correct |
91 ms |
384 KB |
Output is correct |
57 |
Correct |
90 ms |
404 KB |
Output is correct |
58 |
Correct |
115 ms |
504 KB |
Output is correct |
59 |
Correct |
104 ms |
412 KB |
Output is correct |
60 |
Correct |
100 ms |
380 KB |
Output is correct |