Submission #996159

# Submission time Handle Problem Language Result Execution time Memory
996159 2024-06-10T08:21:02 Z vjudge1 Xylophone (JOI18_xylophone) C++17
100 / 100
368 ms 97664 KB
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;

int a[5005],d[5005][5005];

void solve(int n){
	int _=query(1,2);
	for(int i=3; i<=n; i++) d[i-2][i]=query(i-2,i);
	for(int i=2; i<=n; i++) d[i-1][i]=query(i-1,i);
	for(int i=1; i<=n; i++){
		a[1]=i;
		for(int __=-1; __<=1; __+=2){
			vector <int> vis(n+1,0);
			vis[a[1]]++;
			a[2]=a[1]+__*_;
			if(a[2]>=1 and a[2]<=n) vis[a[2]]++;
			int cnt=0;
			for(int j=3; j<=n; j++){
				int v=d[j-2][j];
				int l=d[j-1][j];
				if(v==max(a[j-1],a[j-2])-min(a[j-1],a[j-2])){
					if(a[j-1]>a[j-2]) a[j]=a[j-1]-l;
					else a[j]=a[j-1]+l;
				}else{
					int ifmin=a[j-1]-l;
					int ifmax=a[j-1]+l;
					if(ifmin>0 and max({a[j-2],a[j-1]})-ifmin==v) a[j]=ifmin;
					else a[j]=ifmax;
				}
				if(a[j]>=1 and a[j]<=n) vis[a[j]]++;
			}
			int fir=1,last=0;
			for(int j=1; j<=n; j++) if(a[j]==1) fir=j;
			for(int j=1; j<=n; j++) if(a[j]==n) last=j;
			if(fir>last) continue;
			bool ck=1;
			for(int i=1; i<=n; i++) if(vis[i]!=1) ck=0;
			if(!ck) continue;
			for(int i=1; i<=n; i++) answer(i,a[i]);
			return;
		}
	}
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:18:8: warning: unused variable 'cnt' [-Wunused-variable]
   18 |    int cnt=0;
      |        ^~~
# 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 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 2 ms 2648 KB Output is correct
9 Correct 2 ms 2392 KB Output is correct
10 Correct 2 ms 2648 KB Output is correct
11 Correct 2 ms 2392 KB Output is correct
12 Correct 2 ms 2392 KB Output is correct
13 Correct 2 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 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 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 2 ms 2648 KB Output is correct
9 Correct 2 ms 2392 KB Output is correct
10 Correct 2 ms 2648 KB Output is correct
11 Correct 2 ms 2392 KB Output is correct
12 Correct 2 ms 2392 KB Output is correct
13 Correct 2 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 3 ms 6488 KB Output is correct
17 Correct 7 ms 10740 KB Output is correct
18 Correct 12 ms 16728 KB Output is correct
19 Correct 23 ms 20996 KB Output is correct
20 Correct 20 ms 20824 KB Output is correct
21 Correct 19 ms 20824 KB Output is correct
22 Correct 18 ms 20820 KB Output is correct
23 Correct 11 ms 20996 KB Output is correct
24 Correct 16 ms 21148 KB Output is correct
25 Correct 11 ms 20824 KB Output is correct
26 Correct 18 ms 21000 KB Output is correct
27 Correct 14 ms 21080 KB Output is correct
28 Correct 17 ms 20824 KB Output is correct
29 Correct 19 ms 20992 KB Output is correct
30 Correct 15 ms 21080 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 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 2 ms 2648 KB Output is correct
9 Correct 2 ms 2392 KB Output is correct
10 Correct 2 ms 2648 KB Output is correct
11 Correct 2 ms 2392 KB Output is correct
12 Correct 2 ms 2392 KB Output is correct
13 Correct 2 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 3 ms 6488 KB Output is correct
17 Correct 7 ms 10740 KB Output is correct
18 Correct 12 ms 16728 KB Output is correct
19 Correct 23 ms 20996 KB Output is correct
20 Correct 20 ms 20824 KB Output is correct
21 Correct 19 ms 20824 KB Output is correct
22 Correct 18 ms 20820 KB Output is correct
23 Correct 11 ms 20996 KB Output is correct
24 Correct 16 ms 21148 KB Output is correct
25 Correct 11 ms 20824 KB Output is correct
26 Correct 18 ms 21000 KB Output is correct
27 Correct 14 ms 21080 KB Output is correct
28 Correct 17 ms 20824 KB Output is correct
29 Correct 19 ms 20992 KB Output is correct
30 Correct 15 ms 21080 KB Output is correct
31 Correct 33 ms 43504 KB Output is correct
32 Correct 155 ms 62040 KB Output is correct
33 Correct 147 ms 86864 KB Output is correct
34 Correct 231 ms 97068 KB Output is correct
35 Correct 246 ms 97368 KB Output is correct
36 Correct 60 ms 97104 KB Output is correct
37 Correct 176 ms 97172 KB Output is correct
38 Correct 64 ms 97100 KB Output is correct
39 Correct 92 ms 97392 KB Output is correct
40 Correct 202 ms 97160 KB Output is correct
41 Correct 283 ms 97360 KB Output is correct
42 Correct 45 ms 97292 KB Output is correct
43 Correct 168 ms 97360 KB Output is correct
44 Correct 55 ms 97040 KB Output is correct
45 Correct 154 ms 97280 KB Output is correct
46 Correct 267 ms 97168 KB Output is correct
47 Correct 294 ms 97016 KB Output is correct
48 Correct 66 ms 97360 KB Output is correct
49 Correct 286 ms 97664 KB Output is correct
50 Correct 291 ms 97300 KB Output is correct
51 Correct 173 ms 97504 KB Output is correct
52 Correct 97 ms 97360 KB Output is correct
53 Correct 284 ms 97360 KB Output is correct
54 Correct 252 ms 96996 KB Output is correct
55 Correct 311 ms 97268 KB Output is correct
56 Correct 297 ms 97104 KB Output is correct
57 Correct 285 ms 97388 KB Output is correct
58 Correct 368 ms 97396 KB Output is correct
59 Correct 231 ms 97040 KB Output is correct
60 Correct 189 ms 97360 KB Output is correct