#include <bits/stdc++.h>
using namespace std;
int query(int, int);
void answer(int, int);
void solve(int N){
vector<int> diffs(N+1,0);
for(int i = 1;i<=N-1;++i){
diffs[i] = query(i,i+1);
}
vector<int> nums(N+1,0);
int dir = 1; nums[2] = diffs[1];
for(int i = 1;i<=N-2;++i){
int val = query(i,i+2);
if(val == diffs[i]+diffs[i+1]){ //same direction
nums[i+2] = nums[i+1]+dir*diffs[i+1];
}
else{
dir = (-1)*dir;
nums[i+2] = nums[i+1]+dir*diffs[i+1];
}
}
int minn = 0, maxx = 0;
for(int i = 2;i<=N;++i){
minn = min(minn,nums[i]);
maxx = max(maxx,nums[i]);
}
if(maxx+1-minn > N){
for(int i = 2;i<=N;++i){
nums[i] = (-1)*nums[i];
}
minn = 0;
for(int i = 2;i<=N;++i){
minn = min(minn,nums[i]);
}
for(int i = 1;i<=N;++i){
answer(i,nums[i]+1-minn);
}
}
else{
int pos1 = -1, posN = -1;
for(int i = 1;i<=N;++i){
if(nums[i]+1-minn == 1){
pos1 = i;
}
if(nums[i]+1-minn == N){
posN = i;
}
}
if(posN < pos1){
for(int i = 2;i<=N;++i){
nums[i] = (-1)*nums[i];
}
minn = 0;
for(int i = 2;i<=N;++i){
minn = min(minn,nums[i]);
}
for(int i = 1;i<=N;++i){
answer(i,nums[i]+1-minn);
}
}
else{
for(int i = 1;i<=N;++i){
nums[i] += 1-minn;
answer(i,nums[i]);
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
2 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
2 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
3 ms |
344 KB |
Output is correct |
18 |
Correct |
6 ms |
344 KB |
Output is correct |
19 |
Correct |
9 ms |
600 KB |
Output is correct |
20 |
Correct |
11 ms |
344 KB |
Output is correct |
21 |
Correct |
7 ms |
344 KB |
Output is correct |
22 |
Correct |
11 ms |
440 KB |
Output is correct |
23 |
Correct |
9 ms |
344 KB |
Output is correct |
24 |
Correct |
8 ms |
344 KB |
Output is correct |
25 |
Correct |
7 ms |
344 KB |
Output is correct |
26 |
Correct |
7 ms |
448 KB |
Output is correct |
27 |
Correct |
8 ms |
344 KB |
Output is correct |
28 |
Correct |
8 ms |
600 KB |
Output is correct |
29 |
Correct |
9 ms |
436 KB |
Output is correct |
30 |
Correct |
9 ms |
700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
2 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
3 ms |
344 KB |
Output is correct |
18 |
Correct |
6 ms |
344 KB |
Output is correct |
19 |
Correct |
9 ms |
600 KB |
Output is correct |
20 |
Correct |
11 ms |
344 KB |
Output is correct |
21 |
Correct |
7 ms |
344 KB |
Output is correct |
22 |
Correct |
11 ms |
440 KB |
Output is correct |
23 |
Correct |
9 ms |
344 KB |
Output is correct |
24 |
Correct |
8 ms |
344 KB |
Output is correct |
25 |
Correct |
7 ms |
344 KB |
Output is correct |
26 |
Correct |
7 ms |
448 KB |
Output is correct |
27 |
Correct |
8 ms |
344 KB |
Output is correct |
28 |
Correct |
8 ms |
600 KB |
Output is correct |
29 |
Correct |
9 ms |
436 KB |
Output is correct |
30 |
Correct |
9 ms |
700 KB |
Output is correct |
31 |
Correct |
26 ms |
676 KB |
Output is correct |
32 |
Correct |
25 ms |
600 KB |
Output is correct |
33 |
Correct |
35 ms |
460 KB |
Output is correct |
34 |
Correct |
38 ms |
592 KB |
Output is correct |
35 |
Correct |
54 ms |
448 KB |
Output is correct |
36 |
Correct |
33 ms |
452 KB |
Output is correct |
37 |
Correct |
50 ms |
688 KB |
Output is correct |
38 |
Correct |
47 ms |
444 KB |
Output is correct |
39 |
Correct |
38 ms |
428 KB |
Output is correct |
40 |
Correct |
41 ms |
452 KB |
Output is correct |
41 |
Correct |
47 ms |
452 KB |
Output is correct |
42 |
Correct |
34 ms |
344 KB |
Output is correct |
43 |
Correct |
41 ms |
592 KB |
Output is correct |
44 |
Correct |
42 ms |
448 KB |
Output is correct |
45 |
Correct |
48 ms |
344 KB |
Output is correct |
46 |
Correct |
34 ms |
452 KB |
Output is correct |
47 |
Correct |
52 ms |
464 KB |
Output is correct |
48 |
Correct |
52 ms |
448 KB |
Output is correct |
49 |
Correct |
51 ms |
592 KB |
Output is correct |
50 |
Correct |
43 ms |
688 KB |
Output is correct |
51 |
Correct |
48 ms |
592 KB |
Output is correct |
52 |
Correct |
31 ms |
344 KB |
Output is correct |
53 |
Correct |
38 ms |
456 KB |
Output is correct |
54 |
Correct |
63 ms |
444 KB |
Output is correct |
55 |
Correct |
44 ms |
848 KB |
Output is correct |
56 |
Correct |
48 ms |
344 KB |
Output is correct |
57 |
Correct |
39 ms |
344 KB |
Output is correct |
58 |
Correct |
42 ms |
448 KB |
Output is correct |
59 |
Correct |
51 ms |
448 KB |
Output is correct |
60 |
Correct |
52 ms |
848 KB |
Output is correct |