Submission #381103

# Submission time Handle Problem Language Result Execution time Memory
381103 2021-03-24T13:44:33 Z knightron0 Xylophone (JOI18_xylophone) C++14
100 / 100
124 ms 768 KB
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;

const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;

// int a[MAXN];

// int query(int s, int t){
// 	int mx = -MAXN, mn = MAXN;
// 	for(int i= s;i<=t;i++){
// 		mx = max(mx,a[i]);
// 		mn = min(mn,a[i]);
// 	}
// 	return mx-mn;
// }

void solve(int N){
	int nxt[N+2];
	for(int i=1;i<N;i++){
		nxt[i] = query(i, i+1);
	}
	int x[N+2];
	x[1] = 1;
	for(int i=1;i<N-1;i++){
		int vl = query(i, i+2);
		if(vl == nxt[i] || vl == nxt[i+1]){
			x[i+1] = x[i] ^ 1;
		} else {
			x[i+1] = x[i];
		}
	}
	int b[N+2], c[N+2];
	b[1] = 0, c[1] = 0;
	for(int i= 1;i<N;i++){
		if(x[i] == 1){
			b[i+1] = b[i] + nxt[i];
			c[i+1] = c[i] - nxt[i];
		} else {
			b[i+1] = b[i] - nxt[i];
			c[i+1] = c[i] + nxt[i];
		}
	}
	int mxb = -MAXN; int mxc = -MAXN;
	for(int i = 1;i<=N;i++){
		mxb = max(mxb, b[i]);
		mxc = max(mxc, c[i]);
	}
	int diffb = N-mxb;
	int diffc = N-mxc;
	int idx[2] = {0, 0};
	for(int i= 1;i<=N;i++){
		b[i] += diffb;
		c[i] += diffc;
		if(b[i] == 1) idx[0] = i;
		if(b[i] == N) idx[1] = i;
	}
	int ans[N+2];
	for(int i= 1;i<=N;i++) {
		if(idx[0] < idx[1]){
			ans[i] = b[i];
		} else {
			ans[i] = c[i];
		}
		answer(i, ans[i]);
	}
}


// signed main() {
//     ios_base::sync_with_stdio(false);
//     cin.tie(NULL);
//     #ifdef LOCAL
//     freopen("input.txt", "r", stdin);
//     #endif
//    	int n;
//    	cin>>n;
//    	for(int i= 1;i<=n;i++){
//    		cin>>a[i];
//    	}
//    	solve(n);
//     return 0;
// }





# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 3 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 3 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 8 ms 364 KB Output is correct
18 Correct 14 ms 492 KB Output is correct
19 Correct 18 ms 492 KB Output is correct
20 Correct 16 ms 364 KB Output is correct
21 Correct 11 ms 376 KB Output is correct
22 Correct 23 ms 364 KB Output is correct
23 Correct 16 ms 364 KB Output is correct
24 Correct 17 ms 364 KB Output is correct
25 Correct 18 ms 364 KB Output is correct
26 Correct 17 ms 364 KB Output is correct
27 Correct 23 ms 364 KB Output is correct
28 Correct 19 ms 492 KB Output is correct
29 Correct 26 ms 364 KB Output is correct
30 Correct 17 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 3 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 8 ms 364 KB Output is correct
18 Correct 14 ms 492 KB Output is correct
19 Correct 18 ms 492 KB Output is correct
20 Correct 16 ms 364 KB Output is correct
21 Correct 11 ms 376 KB Output is correct
22 Correct 23 ms 364 KB Output is correct
23 Correct 16 ms 364 KB Output is correct
24 Correct 17 ms 364 KB Output is correct
25 Correct 18 ms 364 KB Output is correct
26 Correct 17 ms 364 KB Output is correct
27 Correct 23 ms 364 KB Output is correct
28 Correct 19 ms 492 KB Output is correct
29 Correct 26 ms 364 KB Output is correct
30 Correct 17 ms 492 KB Output is correct
31 Correct 45 ms 364 KB Output is correct
32 Correct 74 ms 364 KB Output is correct
33 Correct 105 ms 364 KB Output is correct
34 Correct 115 ms 492 KB Output is correct
35 Correct 93 ms 492 KB Output is correct
36 Correct 115 ms 620 KB Output is correct
37 Correct 104 ms 632 KB Output is correct
38 Correct 119 ms 492 KB Output is correct
39 Correct 101 ms 500 KB Output is correct
40 Correct 100 ms 492 KB Output is correct
41 Correct 90 ms 492 KB Output is correct
42 Correct 91 ms 492 KB Output is correct
43 Correct 124 ms 492 KB Output is correct
44 Correct 74 ms 492 KB Output is correct
45 Correct 66 ms 768 KB Output is correct
46 Correct 95 ms 504 KB Output is correct
47 Correct 105 ms 496 KB Output is correct
48 Correct 94 ms 492 KB Output is correct
49 Correct 118 ms 492 KB Output is correct
50 Correct 86 ms 492 KB Output is correct
51 Correct 65 ms 492 KB Output is correct
52 Correct 87 ms 492 KB Output is correct
53 Correct 100 ms 620 KB Output is correct
54 Correct 105 ms 492 KB Output is correct
55 Correct 92 ms 492 KB Output is correct
56 Correct 108 ms 620 KB Output is correct
57 Correct 102 ms 628 KB Output is correct
58 Correct 94 ms 492 KB Output is correct
59 Correct 92 ms 488 KB Output is correct
60 Correct 97 ms 536 KB Output is correct