Submission #331598

# Submission time Handle Problem Language Result Execution time Memory
331598 2020-11-29T05:07:42 Z wind_reaper Xylophone (JOI18_xylophone) C++17
100 / 100
125 ms 620 KB
#include "xylophone.h"
#include <bits/stdc++.h> 
// static int A[5000];

using namespace std; 	

#define all(a) a.begin(), a.end()

void solve(int N) {
	// vector<int> dif1(N - 1), dif2(N - 2); 
	if(N == 2){
		answer(1, 1); 
		answer(2, 2);
		return; 
	}

	vector<int> dif1(N - 1), dif2(N - 2); 
	for(int i = 0; i < N - 1; i++)
		dif1[i] = query(i+1, i+2);
	for(int i = 0; i < N - 2; i++)
		dif2[i] = query(i+1, i+3); 

	vector<int> abs1(N - 1), abs2(N - 1); 

	if(dif2[0] == dif1[0] + dif1[1]){
		abs1[0] = abs1[1] = 1; 
		abs2[0] = abs2[1] = -1; 
	}
	else{
		abs1[0] = abs2[1] = 1; 
		abs2[0] = abs1[1] = -1; 
	}

	for(int i = 1; i < N - 2; i++){
		if(dif2[i] == dif1[i] + dif1[i+1]){
			abs1[i+1] = abs1[i];
			abs2[i+1] = abs2[i];  
		}
		else{
			abs1[i+1] = -abs1[i]; 
			abs2[i+1] = -abs2[i]; 
		}
	}

	vector<int> pref1(N), pref2(N); 

	pref1[0] = pref2[0] = 0; 

	for(int i = 1; i < N; i++){
		pref1[i] = pref1[i-1] + abs1[i-1]*dif1[i-1]; 
		pref2[i] = pref2[i-1] + abs2[i-1]*dif1[i-1];  
	}

	int m1 = max_element(all(pref1)) - pref1.begin(); 
	int n1 = min_element(all(pref1)) - pref1.begin(); 
	if(m1 > n1){
		vector<int> ans(N); 
		ans[0] = N - *max_element(all(pref1)); 

		for(int i = 1; i < N; i++)
			ans[i] = ans[0] + pref1[i]; 

		for(int i = 0; i < N; i++){
			// cout << ans[i] << ' '; 
			answer(i+1, ans[i]);
		}
	}
	else{
		vector<int> ans(N); 
		ans[0] = N - *max_element(all(pref2)); 

		for(int i = 1; i < N; i++)
			ans[i] = ans[0] + pref2[i]; 

		for(int i = 0; i < N; i++){
			// cout << ans[i] << ' '; 
			answer(i+1, ans[i]);
		}
	}
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 3 ms 364 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 3 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 512 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 3 ms 364 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 3 ms 364 KB Output is correct
16 Correct 5 ms 364 KB Output is correct
17 Correct 9 ms 364 KB Output is correct
18 Correct 19 ms 364 KB Output is correct
19 Correct 19 ms 364 KB Output is correct
20 Correct 23 ms 364 KB Output is correct
21 Correct 19 ms 384 KB Output is correct
22 Correct 11 ms 492 KB Output is correct
23 Correct 23 ms 492 KB Output is correct
24 Correct 23 ms 492 KB Output is correct
25 Correct 19 ms 508 KB Output is correct
26 Correct 19 ms 492 KB Output is correct
27 Correct 30 ms 512 KB Output is correct
28 Correct 26 ms 364 KB Output is correct
29 Correct 27 ms 364 KB Output is correct
30 Correct 23 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 512 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 3 ms 364 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 3 ms 364 KB Output is correct
16 Correct 5 ms 364 KB Output is correct
17 Correct 9 ms 364 KB Output is correct
18 Correct 19 ms 364 KB Output is correct
19 Correct 19 ms 364 KB Output is correct
20 Correct 23 ms 364 KB Output is correct
21 Correct 19 ms 384 KB Output is correct
22 Correct 11 ms 492 KB Output is correct
23 Correct 23 ms 492 KB Output is correct
24 Correct 23 ms 492 KB Output is correct
25 Correct 19 ms 508 KB Output is correct
26 Correct 19 ms 492 KB Output is correct
27 Correct 30 ms 512 KB Output is correct
28 Correct 26 ms 364 KB Output is correct
29 Correct 27 ms 364 KB Output is correct
30 Correct 23 ms 364 KB Output is correct
31 Correct 47 ms 364 KB Output is correct
32 Correct 57 ms 364 KB Output is correct
33 Correct 111 ms 396 KB Output is correct
34 Correct 86 ms 492 KB Output is correct
35 Correct 113 ms 492 KB Output is correct
36 Correct 103 ms 544 KB Output is correct
37 Correct 93 ms 416 KB Output is correct
38 Correct 92 ms 492 KB Output is correct
39 Correct 88 ms 544 KB Output is correct
40 Correct 120 ms 492 KB Output is correct
41 Correct 125 ms 492 KB Output is correct
42 Correct 79 ms 620 KB Output is correct
43 Correct 101 ms 544 KB Output is correct
44 Correct 88 ms 492 KB Output is correct
45 Correct 72 ms 544 KB Output is correct
46 Correct 109 ms 616 KB Output is correct
47 Correct 114 ms 620 KB Output is correct
48 Correct 55 ms 544 KB Output is correct
49 Correct 108 ms 492 KB Output is correct
50 Correct 71 ms 544 KB Output is correct
51 Correct 115 ms 544 KB Output is correct
52 Correct 83 ms 620 KB Output is correct
53 Correct 119 ms 492 KB Output is correct
54 Correct 124 ms 620 KB Output is correct
55 Correct 95 ms 620 KB Output is correct
56 Correct 84 ms 620 KB Output is correct
57 Correct 117 ms 492 KB Output is correct
58 Correct 91 ms 492 KB Output is correct
59 Correct 54 ms 544 KB Output is correct
60 Correct 94 ms 416 KB Output is correct