Submission #793104

# Submission time Handle Problem Language Result Execution time Memory
793104 2023-07-25T13:58:20 Z MODDI Xylophone (JOI18_xylophone) C++14
100 / 100
60 ms 304 KB
#include <bits/stdc++.h>
#include "xylophone.h"
//#include "grader.cpp"
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
//static int A[5000];
void solve(int n) {
	int l = 1, r = n; // position where one is at
	while(r-l>1){
		int mid = (l + r) / 2;
		int ans = query(mid, n);
		if(ans == n-1){
			l = mid;
		}
		else
			r = mid;
	}
	answer(l, 1);
	int arr[n+1];
	memset(arr, -1, sizeof arr);
	arr[l] = 1;
	bool vis[n+1];
	memset(vis, false, sizeof vis);
	vis[1] = true;
	if(l + 1 <= n){
		int d = query(l, l+1);
		arr[l+1] = d+1;
		vis[arr[l+1]]=true;
		answer(l+1, arr[l+1]);
	}
	for(int j = l + 2; j <= n; j++){
		int d = query(j-1, j);
		if(arr[j-1] - d < 1 || vis[arr[j-1]-d]){
			vis[arr[j-1]+d] = true;
			arr[j] = arr[j-1] + d;
			answer(j, arr[j]);
		}
		else if(arr[j-1]+d > n || vis[arr[j-1]+d]){
			vis[arr[j-1]-d] = true;
			arr[j] = arr[j-1] - d;
			answer(j, arr[j]);
		}
		else{
			int l = query(j-2, j);
			if(l == max(d, abs(arr[j-1] - arr[j-2]))){
				if(arr[j-2] < arr[j-1]){
					vis[arr[j-1] - d] = true;
					arr[j] = arr[j-1]-d;
					answer(j, arr[j]);
				}
				else{
					vis[arr[j-1]+d] = true;
					arr[j] = arr[j-1]+d;
					answer(j, arr[j]);
				}
			}
			else{
				if(arr[j-2] < arr[j-1]){
					vis[arr[j-1] + d] = true;
					arr[j] = arr[j-1]+d;
					answer(j, arr[j]);
				}
				else{
					vis[arr[j-1]-d] = true;
					arr[j] = arr[j-1]-d;
					answer(j, arr[j]);
				}
			}
		}
	}
	if(l-1 > 0){
		int d = query(l-1, l);
		arr[l-1] = d + 1;
		vis[arr[l-1]] = true;
		answer(l-1, arr[l-1]);
	}
	for(int i = l - 2; i >= 1; i--){
		int d=query(i,i+1);
        if(arr[i+1]-d<1||vis[arr[i+1]-d]){
			arr[i] = arr[i+1] + d;
			vis[arr[i]] = true;
			answer(i, arr[i]);
		}
        else if(arr[i+1]+d>n||vis[arr[i+1]+d]){
			arr[i] = arr[i+1] - d;
			vis[arr[i]] = true;
			answer(i, arr[i]);
		}
        else
        {
            int l=query(i,i+2);
            if(l==max(d,abs(arr[i+1]-arr[i+2])))
            {
                if(arr[i+2]<arr[i+1]){
					arr[i] = arr[i+1] - d;
					vis[arr[i]] = true;
					answer(i, arr[i]);
				}
                else{
					arr[i] = arr[i+1] + d;
					vis[arr[i]] = true;
					answer(i, arr[i]);
				}
            }
            else
            {
                if(arr[i+2]<arr[i+1]){
					arr[i] = arr[i+1] + d;
					vis[arr[i]] = true;
					answer(i, arr[i]);
				}
                else{
					arr[i] = arr[i+1] - d;
					vis[arr[i]] = true;
					answer(i, arr[i]);
				}
            }
        }
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 7 ms 208 KB Output is correct
19 Correct 10 ms 208 KB Output is correct
20 Correct 12 ms 208 KB Output is correct
21 Correct 12 ms 208 KB Output is correct
22 Correct 9 ms 208 KB Output is correct
23 Correct 9 ms 208 KB Output is correct
24 Correct 9 ms 208 KB Output is correct
25 Correct 9 ms 208 KB Output is correct
26 Correct 8 ms 208 KB Output is correct
27 Correct 12 ms 208 KB Output is correct
28 Correct 12 ms 208 KB Output is correct
29 Correct 8 ms 208 KB Output is correct
30 Correct 11 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 7 ms 208 KB Output is correct
19 Correct 10 ms 208 KB Output is correct
20 Correct 12 ms 208 KB Output is correct
21 Correct 12 ms 208 KB Output is correct
22 Correct 9 ms 208 KB Output is correct
23 Correct 9 ms 208 KB Output is correct
24 Correct 9 ms 208 KB Output is correct
25 Correct 9 ms 208 KB Output is correct
26 Correct 8 ms 208 KB Output is correct
27 Correct 12 ms 208 KB Output is correct
28 Correct 12 ms 208 KB Output is correct
29 Correct 8 ms 208 KB Output is correct
30 Correct 11 ms 208 KB Output is correct
31 Correct 16 ms 208 KB Output is correct
32 Correct 31 ms 208 KB Output is correct
33 Correct 47 ms 304 KB Output is correct
34 Correct 53 ms 208 KB Output is correct
35 Correct 48 ms 296 KB Output is correct
36 Correct 43 ms 208 KB Output is correct
37 Correct 43 ms 208 KB Output is correct
38 Correct 31 ms 208 KB Output is correct
39 Correct 25 ms 208 KB Output is correct
40 Correct 46 ms 208 KB Output is correct
41 Correct 53 ms 208 KB Output is correct
42 Correct 32 ms 208 KB Output is correct
43 Correct 42 ms 208 KB Output is correct
44 Correct 38 ms 208 KB Output is correct
45 Correct 45 ms 208 KB Output is correct
46 Correct 41 ms 208 KB Output is correct
47 Correct 38 ms 296 KB Output is correct
48 Correct 49 ms 208 KB Output is correct
49 Correct 38 ms 208 KB Output is correct
50 Correct 43 ms 208 KB Output is correct
51 Correct 56 ms 208 KB Output is correct
52 Correct 52 ms 208 KB Output is correct
53 Correct 39 ms 208 KB Output is correct
54 Correct 50 ms 208 KB Output is correct
55 Correct 24 ms 300 KB Output is correct
56 Correct 60 ms 208 KB Output is correct
57 Correct 53 ms 208 KB Output is correct
58 Correct 39 ms 208 KB Output is correct
59 Correct 48 ms 208 KB Output is correct
60 Correct 28 ms 208 KB Output is correct