#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N=5010;
int n,a[N],x[N],y[N];
VI ans;
//int query(int l,int r) {
// int mn=(1<<29),mx=0;
// rep(i,l,r+1) mn=min(mn,a[i]),mx=max(mx,a[i]);
// return mx-mn;
//}
int check(int r) {
rep(i,1,n+1) {
VI v={i};
rep(j,1,n) {
v.pb(v.back()+x[j]*r);
if (j!=n-1) if (y[j]!=x[j]+x[j+1]) r=(r==-1?1:-1);
}
int px,py;
rep(j,0,n) if (v[j]==1) px=j;
rep(j,0,n) if (v[j]==n) py=j;
if (*min_element(all(v))==1&&*max_element(all(v))==n) {
vector<bool> was(n+1,false);
rep(j,0,n) was[v[j]]=true;
bool ok=true;
rep(j,1,n+1) if (!was[j]) ok=false;
if (ok&&px<py) {
ans=v;
return i;
}
}
}
return -1;
}
void solve(int N) {
n=N;
rep(i,1,n) x[i]=query(i,i+1);
rep(i,1,n-1) y[i]=query(i,i+2);
check(-1);
check(1);
assert(SZ(ans)>0);
// rep(i,0,n) printf("%d ",ans[i]);
rep(i,0,n) answer(i+1,ans[i]);
}
//int main() {
// scanf("%d",&n);
// rep(i,1,n+1) scanf("%d",a+i);
// solve(n);
//}
/*
5
2 1 5 3 4
*/
Compilation message
xylophone.cpp: In function 'int check(int)':
xylophone.cpp:46:14: warning: 'py' may be used uninitialized in this function [-Wmaybe-uninitialized]
46 | if (ok&&px<py) {
| ~~^~~
xylophone.cpp:46:14: warning: 'px' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
2 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
200 KB |
Output is correct |
6 |
Correct |
2 ms |
200 KB |
Output is correct |
7 |
Correct |
2 ms |
200 KB |
Output is correct |
8 |
Correct |
2 ms |
200 KB |
Output is correct |
9 |
Correct |
2 ms |
200 KB |
Output is correct |
10 |
Correct |
2 ms |
200 KB |
Output is correct |
11 |
Correct |
2 ms |
200 KB |
Output is correct |
12 |
Correct |
2 ms |
200 KB |
Output is correct |
13 |
Correct |
2 ms |
200 KB |
Output is correct |
14 |
Correct |
2 ms |
200 KB |
Output is correct |
15 |
Correct |
2 ms |
200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
2 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
200 KB |
Output is correct |
6 |
Correct |
2 ms |
200 KB |
Output is correct |
7 |
Correct |
2 ms |
200 KB |
Output is correct |
8 |
Correct |
2 ms |
200 KB |
Output is correct |
9 |
Correct |
2 ms |
200 KB |
Output is correct |
10 |
Correct |
2 ms |
200 KB |
Output is correct |
11 |
Correct |
2 ms |
200 KB |
Output is correct |
12 |
Correct |
2 ms |
200 KB |
Output is correct |
13 |
Correct |
2 ms |
200 KB |
Output is correct |
14 |
Correct |
2 ms |
200 KB |
Output is correct |
15 |
Correct |
2 ms |
200 KB |
Output is correct |
16 |
Correct |
5 ms |
200 KB |
Output is correct |
17 |
Correct |
11 ms |
200 KB |
Output is correct |
18 |
Correct |
12 ms |
308 KB |
Output is correct |
19 |
Correct |
23 ms |
300 KB |
Output is correct |
20 |
Correct |
29 ms |
300 KB |
Output is correct |
21 |
Correct |
22 ms |
308 KB |
Output is correct |
22 |
Correct |
24 ms |
304 KB |
Output is correct |
23 |
Correct |
24 ms |
304 KB |
Output is correct |
24 |
Correct |
27 ms |
416 KB |
Output is correct |
25 |
Correct |
19 ms |
300 KB |
Output is correct |
26 |
Correct |
30 ms |
304 KB |
Output is correct |
27 |
Correct |
21 ms |
304 KB |
Output is correct |
28 |
Correct |
26 ms |
200 KB |
Output is correct |
29 |
Correct |
28 ms |
304 KB |
Output is correct |
30 |
Correct |
18 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
2 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
200 KB |
Output is correct |
6 |
Correct |
2 ms |
200 KB |
Output is correct |
7 |
Correct |
2 ms |
200 KB |
Output is correct |
8 |
Correct |
2 ms |
200 KB |
Output is correct |
9 |
Correct |
2 ms |
200 KB |
Output is correct |
10 |
Correct |
2 ms |
200 KB |
Output is correct |
11 |
Correct |
2 ms |
200 KB |
Output is correct |
12 |
Correct |
2 ms |
200 KB |
Output is correct |
13 |
Correct |
2 ms |
200 KB |
Output is correct |
14 |
Correct |
2 ms |
200 KB |
Output is correct |
15 |
Correct |
2 ms |
200 KB |
Output is correct |
16 |
Correct |
5 ms |
200 KB |
Output is correct |
17 |
Correct |
11 ms |
200 KB |
Output is correct |
18 |
Correct |
12 ms |
308 KB |
Output is correct |
19 |
Correct |
23 ms |
300 KB |
Output is correct |
20 |
Correct |
29 ms |
300 KB |
Output is correct |
21 |
Correct |
22 ms |
308 KB |
Output is correct |
22 |
Correct |
24 ms |
304 KB |
Output is correct |
23 |
Correct |
24 ms |
304 KB |
Output is correct |
24 |
Correct |
27 ms |
416 KB |
Output is correct |
25 |
Correct |
19 ms |
300 KB |
Output is correct |
26 |
Correct |
30 ms |
304 KB |
Output is correct |
27 |
Correct |
21 ms |
304 KB |
Output is correct |
28 |
Correct |
26 ms |
200 KB |
Output is correct |
29 |
Correct |
28 ms |
304 KB |
Output is correct |
30 |
Correct |
18 ms |
300 KB |
Output is correct |
31 |
Correct |
71 ms |
300 KB |
Output is correct |
32 |
Correct |
143 ms |
300 KB |
Output is correct |
33 |
Correct |
204 ms |
300 KB |
Output is correct |
34 |
Correct |
303 ms |
424 KB |
Output is correct |
35 |
Correct |
286 ms |
420 KB |
Output is correct |
36 |
Correct |
215 ms |
304 KB |
Output is correct |
37 |
Correct |
280 ms |
376 KB |
Output is correct |
38 |
Correct |
165 ms |
428 KB |
Output is correct |
39 |
Correct |
229 ms |
376 KB |
Output is correct |
40 |
Correct |
272 ms |
420 KB |
Output is correct |
41 |
Correct |
298 ms |
640 KB |
Output is correct |
42 |
Correct |
223 ms |
308 KB |
Output is correct |
43 |
Correct |
269 ms |
496 KB |
Output is correct |
44 |
Correct |
193 ms |
304 KB |
Output is correct |
45 |
Correct |
264 ms |
564 KB |
Output is correct |
46 |
Correct |
294 ms |
424 KB |
Output is correct |
47 |
Correct |
344 ms |
428 KB |
Output is correct |
48 |
Correct |
212 ms |
448 KB |
Output is correct |
49 |
Correct |
330 ms |
380 KB |
Output is correct |
50 |
Correct |
327 ms |
432 KB |
Output is correct |
51 |
Correct |
270 ms |
380 KB |
Output is correct |
52 |
Correct |
215 ms |
304 KB |
Output is correct |
53 |
Correct |
329 ms |
428 KB |
Output is correct |
54 |
Correct |
308 ms |
376 KB |
Output is correct |
55 |
Correct |
341 ms |
508 KB |
Output is correct |
56 |
Correct |
347 ms |
428 KB |
Output is correct |
57 |
Correct |
307 ms |
528 KB |
Output is correct |
58 |
Correct |
362 ms |
424 KB |
Output is correct |
59 |
Correct |
283 ms |
288 KB |
Output is correct |
60 |
Correct |
265 ms |
320 KB |
Output is correct |