#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
void solve(int n){
vector<int>diff(n+1);
//diff[i] = A[i]-A[i-1]
vector<int>res0(n+1),res1(n+1);
for(int i=1;i<n;i++)res0[i] = query(i,i+1);
for(int i=1;i<=n-2;i++)res1[i] = query(i,i+2);
diff[2] = res0[1];
for(int i=3;i<=n;i++){
int c = diff[i-1]>0?1:-1;
if(res0[i-1]+res0[i-2] != res1[i-2])c*=-1;
diff[i] = c*res0[i-1];
}
int p = 1;
for(int i=2;i<=n;i++){
diff[i]+=diff[i-1];
if(diff[i] < diff[p])p = i;
}
bool ok = 1;
set<int>s;
int con = 1-diff[p];
vector<int>ans(n+1);
for(int i=1;i<=n;i++){
ans[i] = diff[i]+con;
if(s.count(ans[i]))ok = 0;
if(ans[i] < 1 || ans[i] > n )ok = 0;
if(ans[i] == n && i < p)ok = 0;
s.insert(ans[i]);
}
if(!ok){
con = 1e9;
for(int i=1;i<=n;i++){
diff[i]*=-1;
con = min(diff[i],con);
}
con = 1-con;
}
for(int i=1;i<=n;i++)answer(i,diff[i]+con);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
4 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
288 KB |
Output is correct |
6 |
Correct |
4 ms |
200 KB |
Output is correct |
7 |
Correct |
4 ms |
200 KB |
Output is correct |
8 |
Correct |
3 ms |
200 KB |
Output is correct |
9 |
Correct |
2 ms |
200 KB |
Output is correct |
10 |
Correct |
3 ms |
296 KB |
Output is correct |
11 |
Correct |
4 ms |
200 KB |
Output is correct |
12 |
Correct |
4 ms |
200 KB |
Output is correct |
13 |
Correct |
3 ms |
200 KB |
Output is correct |
14 |
Correct |
4 ms |
200 KB |
Output is correct |
15 |
Correct |
3 ms |
200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
4 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
288 KB |
Output is correct |
6 |
Correct |
4 ms |
200 KB |
Output is correct |
7 |
Correct |
4 ms |
200 KB |
Output is correct |
8 |
Correct |
3 ms |
200 KB |
Output is correct |
9 |
Correct |
2 ms |
200 KB |
Output is correct |
10 |
Correct |
3 ms |
296 KB |
Output is correct |
11 |
Correct |
4 ms |
200 KB |
Output is correct |
12 |
Correct |
4 ms |
200 KB |
Output is correct |
13 |
Correct |
3 ms |
200 KB |
Output is correct |
14 |
Correct |
4 ms |
200 KB |
Output is correct |
15 |
Correct |
3 ms |
200 KB |
Output is correct |
16 |
Correct |
7 ms |
200 KB |
Output is correct |
17 |
Correct |
10 ms |
200 KB |
Output is correct |
18 |
Correct |
16 ms |
320 KB |
Output is correct |
19 |
Correct |
26 ms |
324 KB |
Output is correct |
20 |
Correct |
29 ms |
292 KB |
Output is correct |
21 |
Correct |
32 ms |
320 KB |
Output is correct |
22 |
Correct |
32 ms |
284 KB |
Output is correct |
23 |
Correct |
30 ms |
320 KB |
Output is correct |
24 |
Correct |
29 ms |
300 KB |
Output is correct |
25 |
Correct |
26 ms |
296 KB |
Output is correct |
26 |
Correct |
18 ms |
292 KB |
Output is correct |
27 |
Correct |
10 ms |
308 KB |
Output is correct |
28 |
Correct |
18 ms |
320 KB |
Output is correct |
29 |
Correct |
30 ms |
320 KB |
Output is correct |
30 |
Correct |
26 ms |
424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
4 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
288 KB |
Output is correct |
6 |
Correct |
4 ms |
200 KB |
Output is correct |
7 |
Correct |
4 ms |
200 KB |
Output is correct |
8 |
Correct |
3 ms |
200 KB |
Output is correct |
9 |
Correct |
2 ms |
200 KB |
Output is correct |
10 |
Correct |
3 ms |
296 KB |
Output is correct |
11 |
Correct |
4 ms |
200 KB |
Output is correct |
12 |
Correct |
4 ms |
200 KB |
Output is correct |
13 |
Correct |
3 ms |
200 KB |
Output is correct |
14 |
Correct |
4 ms |
200 KB |
Output is correct |
15 |
Correct |
3 ms |
200 KB |
Output is correct |
16 |
Correct |
7 ms |
200 KB |
Output is correct |
17 |
Correct |
10 ms |
200 KB |
Output is correct |
18 |
Correct |
16 ms |
320 KB |
Output is correct |
19 |
Correct |
26 ms |
324 KB |
Output is correct |
20 |
Correct |
29 ms |
292 KB |
Output is correct |
21 |
Correct |
32 ms |
320 KB |
Output is correct |
22 |
Correct |
32 ms |
284 KB |
Output is correct |
23 |
Correct |
30 ms |
320 KB |
Output is correct |
24 |
Correct |
29 ms |
300 KB |
Output is correct |
25 |
Correct |
26 ms |
296 KB |
Output is correct |
26 |
Correct |
18 ms |
292 KB |
Output is correct |
27 |
Correct |
10 ms |
308 KB |
Output is correct |
28 |
Correct |
18 ms |
320 KB |
Output is correct |
29 |
Correct |
30 ms |
320 KB |
Output is correct |
30 |
Correct |
26 ms |
424 KB |
Output is correct |
31 |
Correct |
36 ms |
320 KB |
Output is correct |
32 |
Correct |
82 ms |
448 KB |
Output is correct |
33 |
Correct |
133 ms |
580 KB |
Output is correct |
34 |
Correct |
46 ms |
600 KB |
Output is correct |
35 |
Correct |
149 ms |
584 KB |
Output is correct |
36 |
Correct |
97 ms |
600 KB |
Output is correct |
37 |
Correct |
93 ms |
588 KB |
Output is correct |
38 |
Correct |
131 ms |
592 KB |
Output is correct |
39 |
Correct |
101 ms |
576 KB |
Output is correct |
40 |
Correct |
137 ms |
592 KB |
Output is correct |
41 |
Correct |
172 ms |
588 KB |
Output is correct |
42 |
Correct |
102 ms |
604 KB |
Output is correct |
43 |
Correct |
144 ms |
704 KB |
Output is correct |
44 |
Correct |
148 ms |
588 KB |
Output is correct |
45 |
Correct |
88 ms |
596 KB |
Output is correct |
46 |
Correct |
134 ms |
588 KB |
Output is correct |
47 |
Correct |
95 ms |
592 KB |
Output is correct |
48 |
Correct |
93 ms |
604 KB |
Output is correct |
49 |
Correct |
143 ms |
588 KB |
Output is correct |
50 |
Correct |
144 ms |
704 KB |
Output is correct |
51 |
Correct |
89 ms |
576 KB |
Output is correct |
52 |
Correct |
125 ms |
596 KB |
Output is correct |
53 |
Correct |
147 ms |
596 KB |
Output is correct |
54 |
Correct |
93 ms |
600 KB |
Output is correct |
55 |
Correct |
158 ms |
588 KB |
Output is correct |
56 |
Correct |
142 ms |
588 KB |
Output is correct |
57 |
Correct |
115 ms |
588 KB |
Output is correct |
58 |
Correct |
132 ms |
588 KB |
Output is correct |
59 |
Correct |
89 ms |
588 KB |
Output is correct |
60 |
Correct |
134 ms |
592 KB |
Output is correct |