Submission #209826

# Submission time Handle Problem Language Result Execution time Memory
209826 2020-03-15T16:20:13 Z amiratou Xylophone (JOI18_xylophone) C++14
100 / 100
72 ms 636 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
static int A[5000];
set<int> used;
void solve(int N) {

	int pos=N;
	int l=0,r=N-1;
	while(l<=r){
		int med=(l+r)>>1;
		if(query(med+1,N)!=(N-1))
			r=med-1;
		else l=med+1,pos=med;
	}
	used.insert(1);
	A[pos]=1;
	answer(pos+1,1);
	for (int i = pos-1; i >= 0; i--)
	{
		int d=query(i+1,i+2);//i-1
		int a=A[i+1]+d,b=A[i+1]-d;
		if((a<=0)||(a>N)||used.find(a)!=used.end()){A[i]=b,used.insert(b),answer(i+1,b);continue;}
		if((b<=0)||(b>N)||used.find(b)!=used.end()){A[i]=a,used.insert(a),answer(i+1,a);continue;}
		int h=query(i+1,i+3),val;
		if(h!=(abs(A[i+1]-A[i+2])+d)){
			if(A[i+1]<A[i+2])val=a;
			else val=b;
		}
		else{
			if(A[i+1]<A[i+2])val=b;
			else val=a;
		}
		A[i]=val;
		used.insert(val);
		answer(i+1,val);
	}
	for (int i = pos+1; i < N; i++)
	{
		int d=query(i,i+1);//i-1
		int a=A[i-1]+d,b=A[i-1]-d;
		if((a<=0)||(a>N)||used.find(a)!=used.end()){A[i]=b,used.insert(b),answer(i+1,b);continue;}
		if((b<=0)||(b>N)||used.find(b)!=used.end()){A[i]=a,used.insert(a),answer(i+1,a);continue;}
		int h=query(i-1,i+1),val;
		if(h!=(abs(A[i-2]-A[i-1])+d)){
			if(A[i-2]<A[i-1])val=b;
			else val=a;
		}
		else{
			if(A[i-2]<A[i-1])val=a;
			else val=b;
		}
		A[i]=val;
		used.insert(val);
		answer(i+1,val);
	}

}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 6 ms 248 KB Output is correct
5 Correct 5 ms 248 KB Output is correct
6 Correct 6 ms 248 KB Output is correct
7 Correct 6 ms 248 KB Output is correct
8 Correct 6 ms 380 KB Output is correct
9 Correct 6 ms 248 KB Output is correct
10 Correct 6 ms 248 KB Output is correct
11 Correct 7 ms 248 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 5 ms 328 KB Output is correct
15 Correct 6 ms 248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 6 ms 248 KB Output is correct
5 Correct 5 ms 248 KB Output is correct
6 Correct 6 ms 248 KB Output is correct
7 Correct 6 ms 248 KB Output is correct
8 Correct 6 ms 380 KB Output is correct
9 Correct 6 ms 248 KB Output is correct
10 Correct 6 ms 248 KB Output is correct
11 Correct 7 ms 248 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 5 ms 328 KB Output is correct
15 Correct 6 ms 248 KB Output is correct
16 Correct 8 ms 376 KB Output is correct
17 Correct 11 ms 376 KB Output is correct
18 Correct 18 ms 248 KB Output is correct
19 Correct 18 ms 376 KB Output is correct
20 Correct 17 ms 248 KB Output is correct
21 Correct 18 ms 248 KB Output is correct
22 Correct 19 ms 376 KB Output is correct
23 Correct 15 ms 376 KB Output is correct
24 Correct 10 ms 404 KB Output is correct
25 Correct 15 ms 248 KB Output is correct
26 Correct 19 ms 248 KB Output is correct
27 Correct 17 ms 376 KB Output is correct
28 Correct 17 ms 376 KB Output is correct
29 Correct 17 ms 248 KB Output is correct
30 Correct 18 ms 248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 6 ms 248 KB Output is correct
5 Correct 5 ms 248 KB Output is correct
6 Correct 6 ms 248 KB Output is correct
7 Correct 6 ms 248 KB Output is correct
8 Correct 6 ms 380 KB Output is correct
9 Correct 6 ms 248 KB Output is correct
10 Correct 6 ms 248 KB Output is correct
11 Correct 7 ms 248 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 5 ms 328 KB Output is correct
15 Correct 6 ms 248 KB Output is correct
16 Correct 8 ms 376 KB Output is correct
17 Correct 11 ms 376 KB Output is correct
18 Correct 18 ms 248 KB Output is correct
19 Correct 18 ms 376 KB Output is correct
20 Correct 17 ms 248 KB Output is correct
21 Correct 18 ms 248 KB Output is correct
22 Correct 19 ms 376 KB Output is correct
23 Correct 15 ms 376 KB Output is correct
24 Correct 10 ms 404 KB Output is correct
25 Correct 15 ms 248 KB Output is correct
26 Correct 19 ms 248 KB Output is correct
27 Correct 17 ms 376 KB Output is correct
28 Correct 17 ms 376 KB Output is correct
29 Correct 17 ms 248 KB Output is correct
30 Correct 18 ms 248 KB Output is correct
31 Correct 31 ms 504 KB Output is correct
32 Correct 45 ms 456 KB Output is correct
33 Correct 55 ms 504 KB Output is correct
34 Correct 65 ms 632 KB Output is correct
35 Correct 66 ms 504 KB Output is correct
36 Correct 52 ms 524 KB Output is correct
37 Correct 56 ms 632 KB Output is correct
38 Correct 57 ms 504 KB Output is correct
39 Correct 59 ms 504 KB Output is correct
40 Correct 68 ms 632 KB Output is correct
41 Correct 68 ms 632 KB Output is correct
42 Correct 55 ms 504 KB Output is correct
43 Correct 34 ms 568 KB Output is correct
44 Correct 57 ms 620 KB Output is correct
45 Correct 61 ms 504 KB Output is correct
46 Correct 66 ms 504 KB Output is correct
47 Correct 67 ms 504 KB Output is correct
48 Correct 66 ms 504 KB Output is correct
49 Correct 67 ms 484 KB Output is correct
50 Correct 72 ms 632 KB Output is correct
51 Correct 64 ms 484 KB Output is correct
52 Correct 66 ms 632 KB Output is correct
53 Correct 72 ms 504 KB Output is correct
54 Correct 68 ms 556 KB Output is correct
55 Correct 71 ms 636 KB Output is correct
56 Correct 64 ms 632 KB Output is correct
57 Correct 63 ms 632 KB Output is correct
58 Correct 65 ms 504 KB Output is correct
59 Correct 64 ms 508 KB Output is correct
60 Correct 64 ms 504 KB Output is correct