#include <bits/stdc++.h>
using namespace std;
#include "xylophone.h"
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(a) a.begin(), a.end()
#define endl "\n"
static int A[5000];
void solve(int n){
vector<int> diff(n+1);
FOR(i,1,n){
diff[i] = query(i, i+1);
}
vector<int> type(n+1, -1);
type[1] = 1;
FOR(i,1,n-1){
int e = query(i, i+2);
if (e == diff[i]+diff[i+1]){
type[i+1] = type[i];
}else{
type[i+1] = type[i]^1;
}
}
vector<int> a(n+1);
FOR(i,1,n){
if (type[i] == 1){
a[i+1] = a[i]+diff[i];
}else{
a[i+1] = a[i]-diff[i];
}
}
int mini = 1e9; int maxi = 0;
int minind = 0; int maxind = 0;
FOR(i,1,n+1){
if (a[i] < mini){
minind = i;
}
if (a[i] > maxi){
maxind = i;
}
mini = min(mini, a[i]);
maxi = max(maxi, a[i]);
}
// printVector(a);
if (maxi - mini == n-1 && maxind > minind){
FOR(i,1,n+1){
answer(i, a[i]-(mini-1));
}
return;
}
a.clear();a.resize(n+1);
FOR(i,1,n){
if (type[i] == 1){
a[i+1] = a[i]-diff[i];
}else{
a[i+1] = a[i]+diff[i];
}
}
mini = 1e9; maxi = 0;
FOR(i,1,n+1){
mini = min(mini, a[i]);maxi = max(maxi, a[i]);
}
FOR(i,1,n+1){
answer(i, a[i]-(mini-1));
}
return;
}
Compilation message
xylophone.cpp:9:12: warning: 'A' defined but not used [-Wunused-variable]
9 | static int A[5000];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
5 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
336 KB |
Output is correct |
6 |
Correct |
4 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
4 ms |
336 KB |
Output is correct |
9 |
Correct |
4 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
336 KB |
Output is correct |
11 |
Correct |
4 ms |
336 KB |
Output is correct |
12 |
Correct |
4 ms |
336 KB |
Output is correct |
13 |
Correct |
3 ms |
336 KB |
Output is correct |
14 |
Correct |
4 ms |
336 KB |
Output is correct |
15 |
Correct |
4 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
5 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
336 KB |
Output is correct |
6 |
Correct |
4 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
4 ms |
336 KB |
Output is correct |
9 |
Correct |
4 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
336 KB |
Output is correct |
11 |
Correct |
4 ms |
336 KB |
Output is correct |
12 |
Correct |
4 ms |
336 KB |
Output is correct |
13 |
Correct |
3 ms |
336 KB |
Output is correct |
14 |
Correct |
4 ms |
336 KB |
Output is correct |
15 |
Correct |
4 ms |
336 KB |
Output is correct |
16 |
Correct |
8 ms |
436 KB |
Output is correct |
17 |
Correct |
14 ms |
444 KB |
Output is correct |
18 |
Correct |
23 ms |
336 KB |
Output is correct |
19 |
Correct |
29 ms |
336 KB |
Output is correct |
20 |
Correct |
26 ms |
444 KB |
Output is correct |
21 |
Correct |
28 ms |
688 KB |
Output is correct |
22 |
Correct |
29 ms |
584 KB |
Output is correct |
23 |
Correct |
24 ms |
436 KB |
Output is correct |
24 |
Correct |
33 ms |
592 KB |
Output is correct |
25 |
Correct |
30 ms |
584 KB |
Output is correct |
26 |
Correct |
29 ms |
336 KB |
Output is correct |
27 |
Correct |
24 ms |
432 KB |
Output is correct |
28 |
Correct |
25 ms |
444 KB |
Output is correct |
29 |
Correct |
24 ms |
336 KB |
Output is correct |
30 |
Correct |
26 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
5 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
336 KB |
Output is correct |
6 |
Correct |
4 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
4 ms |
336 KB |
Output is correct |
9 |
Correct |
4 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
336 KB |
Output is correct |
11 |
Correct |
4 ms |
336 KB |
Output is correct |
12 |
Correct |
4 ms |
336 KB |
Output is correct |
13 |
Correct |
3 ms |
336 KB |
Output is correct |
14 |
Correct |
4 ms |
336 KB |
Output is correct |
15 |
Correct |
4 ms |
336 KB |
Output is correct |
16 |
Correct |
8 ms |
436 KB |
Output is correct |
17 |
Correct |
14 ms |
444 KB |
Output is correct |
18 |
Correct |
23 ms |
336 KB |
Output is correct |
19 |
Correct |
29 ms |
336 KB |
Output is correct |
20 |
Correct |
26 ms |
444 KB |
Output is correct |
21 |
Correct |
28 ms |
688 KB |
Output is correct |
22 |
Correct |
29 ms |
584 KB |
Output is correct |
23 |
Correct |
24 ms |
436 KB |
Output is correct |
24 |
Correct |
33 ms |
592 KB |
Output is correct |
25 |
Correct |
30 ms |
584 KB |
Output is correct |
26 |
Correct |
29 ms |
336 KB |
Output is correct |
27 |
Correct |
24 ms |
432 KB |
Output is correct |
28 |
Correct |
25 ms |
444 KB |
Output is correct |
29 |
Correct |
24 ms |
336 KB |
Output is correct |
30 |
Correct |
26 ms |
600 KB |
Output is correct |
31 |
Correct |
75 ms |
448 KB |
Output is correct |
32 |
Correct |
103 ms |
448 KB |
Output is correct |
33 |
Correct |
136 ms |
468 KB |
Output is correct |
34 |
Correct |
170 ms |
708 KB |
Output is correct |
35 |
Correct |
192 ms |
444 KB |
Output is correct |
36 |
Correct |
197 ms |
708 KB |
Output is correct |
37 |
Correct |
192 ms |
704 KB |
Output is correct |
38 |
Correct |
157 ms |
464 KB |
Output is correct |
39 |
Correct |
167 ms |
468 KB |
Output is correct |
40 |
Correct |
177 ms |
504 KB |
Output is correct |
41 |
Correct |
174 ms |
708 KB |
Output is correct |
42 |
Correct |
173 ms |
584 KB |
Output is correct |
43 |
Correct |
175 ms |
472 KB |
Output is correct |
44 |
Correct |
170 ms |
708 KB |
Output is correct |
45 |
Correct |
169 ms |
704 KB |
Output is correct |
46 |
Correct |
186 ms |
464 KB |
Output is correct |
47 |
Correct |
165 ms |
840 KB |
Output is correct |
48 |
Correct |
196 ms |
504 KB |
Output is correct |
49 |
Correct |
182 ms |
444 KB |
Output is correct |
50 |
Correct |
173 ms |
468 KB |
Output is correct |
51 |
Correct |
180 ms |
584 KB |
Output is correct |
52 |
Correct |
177 ms |
468 KB |
Output is correct |
53 |
Correct |
181 ms |
476 KB |
Output is correct |
54 |
Correct |
182 ms |
472 KB |
Output is correct |
55 |
Correct |
181 ms |
464 KB |
Output is correct |
56 |
Correct |
184 ms |
464 KB |
Output is correct |
57 |
Correct |
186 ms |
472 KB |
Output is correct |
58 |
Correct |
174 ms |
604 KB |
Output is correct |
59 |
Correct |
180 ms |
472 KB |
Output is correct |
60 |
Correct |
176 ms |
468 KB |
Output is correct |