#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int>vi;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
#define FOR(i,a,b) for(int i=a; i<b; i++)
#define ROF(i,a,b) for(int i=b-1; i>=a; i--)
void ckmin(int &x, int y){x=min(x,y);}
//------------------------------------
int N;
bool check(vi a){
int idx,idxx;
FOR(i,1,N+1){
if(a[i]==1) idx=i;
else if(a[i]==N) idxx=i;
}
return idx<idxx;
}
void solve(int N){
::N=N;
vi a(N),b(N-1);
FOR(i,1,N){
a[i]=query(i,i+1);
if(i!=N-1) b[i]=query(i,i+2);
}
vi s(N); s[1]=1;
FOR(i,1,N-1){
if(a[i]+a[i+1]==b[i]){
s[i+1]=s[i];
}
else{
s[i+1]=-s[i];
}
}
vi ans(N+1);
ans[1]=1;
FOR(i,1,N){
ans[i+1]=ans[i]+s[i]*a[i];
}
int mn=1e9;
FOR(i,1,N+1) ckmin(mn,ans[i]);
FOR(i,1,N+1) ans[i]-=mn-1;
if(!check(ans)){
FOR(i,1,N) s[i]=-s[i];
ans[1]=1;
FOR(i,1,N){
ans[i+1]=ans[i]+s[i]*a[i];
}
mn=1e9;
FOR(i,1,N+1) ckmin(mn,ans[i]);
FOR(i,1,N+1) ans[i]-=mn-1;
}
FOR(i,1,N+1) answer(i,ans[i]);
}
Compilation message
xylophone.cpp: In function 'bool check(vi)':
xylophone.cpp:26:13: warning: 'idxx' may be used uninitialized in this function [-Wmaybe-uninitialized]
26 | return idx<idxx;
| ^~~~
xylophone.cpp:26:13: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:57:2: warning: 'idxx' may be used uninitialized in this function [-Wmaybe-uninitialized]
57 | if(!check(ans)){
| ^~
xylophone.cpp:57:2: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
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 |
3 ms |
200 KB |
Output is correct |
6 |
Correct |
3 ms |
200 KB |
Output is correct |
7 |
Correct |
2 ms |
200 KB |
Output is correct |
8 |
Correct |
3 ms |
200 KB |
Output is correct |
9 |
Correct |
4 ms |
288 KB |
Output is correct |
10 |
Correct |
3 ms |
200 KB |
Output is correct |
11 |
Correct |
3 ms |
200 KB |
Output is correct |
12 |
Correct |
3 ms |
200 KB |
Output is correct |
13 |
Correct |
2 ms |
200 KB |
Output is correct |
14 |
Correct |
4 ms |
200 KB |
Output is correct |
15 |
Correct |
4 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 |
3 ms |
200 KB |
Output is correct |
6 |
Correct |
3 ms |
200 KB |
Output is correct |
7 |
Correct |
2 ms |
200 KB |
Output is correct |
8 |
Correct |
3 ms |
200 KB |
Output is correct |
9 |
Correct |
4 ms |
288 KB |
Output is correct |
10 |
Correct |
3 ms |
200 KB |
Output is correct |
11 |
Correct |
3 ms |
200 KB |
Output is correct |
12 |
Correct |
3 ms |
200 KB |
Output is correct |
13 |
Correct |
2 ms |
200 KB |
Output is correct |
14 |
Correct |
4 ms |
200 KB |
Output is correct |
15 |
Correct |
4 ms |
200 KB |
Output is correct |
16 |
Correct |
5 ms |
200 KB |
Output is correct |
17 |
Correct |
5 ms |
296 KB |
Output is correct |
18 |
Correct |
12 ms |
284 KB |
Output is correct |
19 |
Correct |
18 ms |
200 KB |
Output is correct |
20 |
Correct |
28 ms |
288 KB |
Output is correct |
21 |
Correct |
24 ms |
292 KB |
Output is correct |
22 |
Correct |
25 ms |
288 KB |
Output is correct |
23 |
Correct |
19 ms |
296 KB |
Output is correct |
24 |
Correct |
25 ms |
276 KB |
Output is correct |
25 |
Correct |
24 ms |
292 KB |
Output is correct |
26 |
Correct |
23 ms |
292 KB |
Output is correct |
27 |
Correct |
22 ms |
200 KB |
Output is correct |
28 |
Correct |
20 ms |
280 KB |
Output is correct |
29 |
Correct |
26 ms |
280 KB |
Output is correct |
30 |
Correct |
19 ms |
296 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 |
3 ms |
200 KB |
Output is correct |
6 |
Correct |
3 ms |
200 KB |
Output is correct |
7 |
Correct |
2 ms |
200 KB |
Output is correct |
8 |
Correct |
3 ms |
200 KB |
Output is correct |
9 |
Correct |
4 ms |
288 KB |
Output is correct |
10 |
Correct |
3 ms |
200 KB |
Output is correct |
11 |
Correct |
3 ms |
200 KB |
Output is correct |
12 |
Correct |
3 ms |
200 KB |
Output is correct |
13 |
Correct |
2 ms |
200 KB |
Output is correct |
14 |
Correct |
4 ms |
200 KB |
Output is correct |
15 |
Correct |
4 ms |
200 KB |
Output is correct |
16 |
Correct |
5 ms |
200 KB |
Output is correct |
17 |
Correct |
5 ms |
296 KB |
Output is correct |
18 |
Correct |
12 ms |
284 KB |
Output is correct |
19 |
Correct |
18 ms |
200 KB |
Output is correct |
20 |
Correct |
28 ms |
288 KB |
Output is correct |
21 |
Correct |
24 ms |
292 KB |
Output is correct |
22 |
Correct |
25 ms |
288 KB |
Output is correct |
23 |
Correct |
19 ms |
296 KB |
Output is correct |
24 |
Correct |
25 ms |
276 KB |
Output is correct |
25 |
Correct |
24 ms |
292 KB |
Output is correct |
26 |
Correct |
23 ms |
292 KB |
Output is correct |
27 |
Correct |
22 ms |
200 KB |
Output is correct |
28 |
Correct |
20 ms |
280 KB |
Output is correct |
29 |
Correct |
26 ms |
280 KB |
Output is correct |
30 |
Correct |
19 ms |
296 KB |
Output is correct |
31 |
Correct |
60 ms |
288 KB |
Output is correct |
32 |
Correct |
67 ms |
320 KB |
Output is correct |
33 |
Correct |
100 ms |
320 KB |
Output is correct |
34 |
Correct |
81 ms |
328 KB |
Output is correct |
35 |
Correct |
129 ms |
328 KB |
Output is correct |
36 |
Correct |
130 ms |
408 KB |
Output is correct |
37 |
Correct |
85 ms |
328 KB |
Output is correct |
38 |
Correct |
105 ms |
424 KB |
Output is correct |
39 |
Correct |
90 ms |
320 KB |
Output is correct |
40 |
Correct |
74 ms |
328 KB |
Output is correct |
41 |
Correct |
123 ms |
308 KB |
Output is correct |
42 |
Correct |
115 ms |
328 KB |
Output is correct |
43 |
Correct |
105 ms |
308 KB |
Output is correct |
44 |
Correct |
96 ms |
320 KB |
Output is correct |
45 |
Correct |
89 ms |
328 KB |
Output is correct |
46 |
Correct |
93 ms |
308 KB |
Output is correct |
47 |
Correct |
132 ms |
328 KB |
Output is correct |
48 |
Correct |
102 ms |
308 KB |
Output is correct |
49 |
Correct |
45 ms |
428 KB |
Output is correct |
50 |
Correct |
104 ms |
328 KB |
Output is correct |
51 |
Correct |
96 ms |
328 KB |
Output is correct |
52 |
Correct |
105 ms |
328 KB |
Output is correct |
53 |
Correct |
138 ms |
320 KB |
Output is correct |
54 |
Correct |
137 ms |
328 KB |
Output is correct |
55 |
Correct |
143 ms |
328 KB |
Output is correct |
56 |
Correct |
120 ms |
328 KB |
Output is correct |
57 |
Correct |
120 ms |
316 KB |
Output is correct |
58 |
Correct |
86 ms |
308 KB |
Output is correct |
59 |
Correct |
81 ms |
328 KB |
Output is correct |
60 |
Correct |
86 ms |
320 KB |
Output is correct |