Submission #1016171

# Submission time Handle Problem Language Result Execution time Memory
1016171 2024-07-07T13:18:52 Z vjudge1 Xylophone (JOI18_xylophone) C++17
100 / 100
46 ms 1372 KB
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;

void solve(int N) {
	int a[N+1];
	memset(a, 0, sizeof(a));
	set<int> s;
	// binary search pos of 1
	int lower = 1, upper = N;
	while(upper-lower>1){
		int mid = (upper+lower)/2;
		int x = query(mid, N);
		if(x==N-1) lower = mid;
		else upper = mid;
	}
	int pos1 = lower;
	a[pos1] = 1;
	s.insert(1);
	if(pos1<N){
		// go to right
		int prev = query(pos1, pos1+1);
		a[pos1+1] = 1 + prev;
		s.insert(a[pos1+1]);
		for (int i=pos1+1; i<N; i++){
			int next = query(i, i+1);
			if(a[i]+next>N) a[i+1] = a[i]-next;
			else if(a[i]-next<1) a[i+1] = a[i]+next;
			else if(s.find(a[i]+next)!=s.end()) a[i+1] = a[i]-next;
			else if(s.find(a[i]-next)!=s.end()) a[i+1] = a[i]+next;
			else{
				int cur = query(i-1, i+1);
				if(cur==prev+next){
					if(a[i]>a[i-1]) a[i+1] = a[i]+next;
					else a[i+1] = a[i]-next;
				}
				else{
					if(a[i]>a[i-1]) a[i+1] = a[i]-next;
					else a[i+1] = a[i]+next;
				}
			}
			prev = next;
			s.insert(a[i+1]);
		}
	}
	if(pos1>1){
		// go to left
		int prev = query(pos1-1, pos1);
		a[pos1-1] = 1 + prev;
		s.insert(a[pos1-1]);
		for (int i=pos1-1; i>1; i--){
			int next = query(i-1, i);
			if(a[i]+next>N) a[i-1] = a[i]-next;
			else if(a[i]-next<1) a[i-1] = a[i]+next;
			else if(s.find(a[i]+next)!=s.end()) a[i-1] = a[i]-next;
			else if(s.find(a[i]-next)!=s.end()) a[i-1] = a[i]+next;
			else{
				int cur = query(i-1, i+1);
				if(cur==prev+next){
					if(a[i]>a[i+1]) a[i-1] = a[i]+next;
					else a[i-1] = a[i]-next;
				}
				else{
					if(a[i]>a[i+1]) a[i-1] = a[i]-next;
					else a[i-1] = a[i]+next;
				}
			}
			prev = next;
			s.insert(a[i-1]);
		}
	}
	for (int i=1; i<=N; i++) answer(i, a[i]);
	return;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 432 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 432 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 5 ms 344 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 6 ms 344 KB Output is correct
21 Correct 6 ms 484 KB Output is correct
22 Correct 6 ms 344 KB Output is correct
23 Correct 5 ms 476 KB Output is correct
24 Correct 7 ms 600 KB Output is correct
25 Correct 5 ms 472 KB Output is correct
26 Correct 9 ms 608 KB Output is correct
27 Correct 9 ms 600 KB Output is correct
28 Correct 4 ms 600 KB Output is correct
29 Correct 9 ms 344 KB Output is correct
30 Correct 9 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 432 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 5 ms 344 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 6 ms 344 KB Output is correct
21 Correct 6 ms 484 KB Output is correct
22 Correct 6 ms 344 KB Output is correct
23 Correct 5 ms 476 KB Output is correct
24 Correct 7 ms 600 KB Output is correct
25 Correct 5 ms 472 KB Output is correct
26 Correct 9 ms 608 KB Output is correct
27 Correct 9 ms 600 KB Output is correct
28 Correct 4 ms 600 KB Output is correct
29 Correct 9 ms 344 KB Output is correct
30 Correct 9 ms 456 KB Output is correct
31 Correct 13 ms 484 KB Output is correct
32 Correct 33 ms 344 KB Output is correct
33 Correct 44 ms 864 KB Output is correct
34 Correct 36 ms 856 KB Output is correct
35 Correct 29 ms 844 KB Output is correct
36 Correct 25 ms 1372 KB Output is correct
37 Correct 23 ms 592 KB Output is correct
38 Correct 30 ms 732 KB Output is correct
39 Correct 43 ms 600 KB Output is correct
40 Correct 39 ms 1024 KB Output is correct
41 Correct 36 ms 748 KB Output is correct
42 Correct 32 ms 792 KB Output is correct
43 Correct 24 ms 856 KB Output is correct
44 Correct 30 ms 812 KB Output is correct
45 Correct 34 ms 848 KB Output is correct
46 Correct 38 ms 832 KB Output is correct
47 Correct 44 ms 888 KB Output is correct
48 Correct 36 ms 824 KB Output is correct
49 Correct 35 ms 768 KB Output is correct
50 Correct 46 ms 852 KB Output is correct
51 Correct 34 ms 1052 KB Output is correct
52 Correct 33 ms 872 KB Output is correct
53 Correct 37 ms 752 KB Output is correct
54 Correct 38 ms 592 KB Output is correct
55 Correct 29 ms 592 KB Output is correct
56 Correct 38 ms 848 KB Output is correct
57 Correct 39 ms 748 KB Output is correct
58 Correct 29 ms 764 KB Output is correct
59 Correct 36 ms 888 KB Output is correct
60 Correct 33 ms 460 KB Output is correct