Submission #100784

# Submission time Handle Problem Language Result Execution time Memory
100784 2019-03-14T10:56:17 Z JPN20 Candies (JOI18_candies) C++17
100 / 100
4102 ms 18856 KB
#include <bits/stdc++.h>
using namespace std;

struct Node{
	vector<long long> p[4];
};

vector<long long> check(vector<long long>A, vector<long long>B) {
	vector<long long>ans;
	
	int cnt = 3, L = 2; while (L < (int)(A.size() + B.size())) { L *= 3; L /= 2; cnt++; }
	
	int maxs = A.size() - 1 + B.size() - 1;
	for (int i = 0; i <= maxs; i++) {
		int L = 0, R = A.size(), c1, c2;
		if (i >= (int)B.size()) L = i - ((int)B.size() - 1);
		if (i < (int)A.size()) R = i + 1;
		
		int cl = L, cr = R;
		
		for (int j = 0; j < cnt; j++) {
			c1 = (L + L + R) / 3;
			c2 = (L + R + R) / 3;
			long long E1 = A[c1] + B[i - c1];
			long long E2 = A[c2] + B[i - c2];
			if (E1 < E2) L = c1;
			else R = c2;
		}
		
		long long rets = 0;
		for (int j = -3; j <= 3; j++) {
			int ss = c1 + j; if (ss < cl || cr <= ss) continue;
			rets = max(rets, A[ss] + B[i - ss]);
		}
		ans.push_back(rets);
	}
	return ans;
}

Node calc(Node A1, Node A2) {
	// i = 1 or 3 : 一番後ろに飴がある
	// i = 2 or 3 : 一番前に飴がある
	Node E;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			if ((i == 1 || i == 3) && (j == 2 || j == 3)) continue;
			vector<long long> I = check(A1.p[i], A2.p[j]);
			
			int ty = 0; if (i == 2 || i == 3) ty += 2; if (j == 1 || j == 3) ty += 1;
			for (int j = 0; j < (int)I.size(); j++) {
				if ((int)E.p[ty].size() == j) E.p[ty].push_back(I[j]);
				else E.p[ty][j] = max(E.p[ty][j], I[j]);
			}
		}
	}
	return E;
}

long long N, A[200009], C[200009];

Node solve(int l, int r) {
	if (l + 1 == r) {
		Node I;
		I.p[0] = {0};
		I.p[1] = {0};
		I.p[2] = {0};
		I.p[3] = {0, A[l]};
		return I;
	}
	
	Node LL = solve(l, (l + r) / 2);
	Node RR = solve((l + r) / 2, r);
	return calc(LL, RR);
}

int main() {
	scanf("%lld", &N);
	for (int i = 1; i <= N; i++) {
		scanf("%lld", &A[i]);
	}
	
	Node T = solve(1, N + 1);
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < T.p[i].size(); j++) C[j] = max(C[j], T.p[i][j]);
	}
	
	for (int i = 1; i <= (N + 1) / 2; i++) printf("%lld\n", C[i]);
	return 0;
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:84:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < T.p[i].size(); j++) C[j] = max(C[j], T.p[i][j]);
                   ~~^~~~~~~~~~~~~~~
candies.cpp:77:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &N);
  ~~~~~^~~~~~~~~~~~
candies.cpp:79:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &A[i]);
   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 25 ms 512 KB Output is correct
2 Correct 23 ms 504 KB Output is correct
3 Correct 23 ms 512 KB Output is correct
4 Correct 22 ms 504 KB Output is correct
5 Correct 22 ms 504 KB Output is correct
6 Correct 26 ms 504 KB Output is correct
7 Correct 22 ms 480 KB Output is correct
8 Correct 21 ms 512 KB Output is correct
9 Correct 21 ms 512 KB Output is correct
10 Correct 21 ms 512 KB Output is correct
11 Correct 21 ms 512 KB Output is correct
12 Correct 25 ms 504 KB Output is correct
13 Correct 22 ms 504 KB Output is correct
14 Correct 22 ms 424 KB Output is correct
15 Correct 21 ms 512 KB Output is correct
16 Correct 22 ms 512 KB Output is correct
17 Correct 35 ms 504 KB Output is correct
18 Correct 22 ms 444 KB Output is correct
19 Correct 29 ms 504 KB Output is correct
20 Correct 21 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 512 KB Output is correct
2 Correct 23 ms 504 KB Output is correct
3 Correct 23 ms 512 KB Output is correct
4 Correct 22 ms 504 KB Output is correct
5 Correct 22 ms 504 KB Output is correct
6 Correct 26 ms 504 KB Output is correct
7 Correct 22 ms 480 KB Output is correct
8 Correct 21 ms 512 KB Output is correct
9 Correct 21 ms 512 KB Output is correct
10 Correct 21 ms 512 KB Output is correct
11 Correct 21 ms 512 KB Output is correct
12 Correct 25 ms 504 KB Output is correct
13 Correct 22 ms 504 KB Output is correct
14 Correct 22 ms 424 KB Output is correct
15 Correct 21 ms 512 KB Output is correct
16 Correct 22 ms 512 KB Output is correct
17 Correct 35 ms 504 KB Output is correct
18 Correct 22 ms 444 KB Output is correct
19 Correct 29 ms 504 KB Output is correct
20 Correct 21 ms 512 KB Output is correct
21 Correct 4102 ms 15356 KB Output is correct
22 Correct 4030 ms 17416 KB Output is correct
23 Correct 4070 ms 17260 KB Output is correct
24 Correct 3759 ms 17184 KB Output is correct
25 Correct 3784 ms 17176 KB Output is correct
26 Correct 3693 ms 17052 KB Output is correct
27 Correct 3901 ms 17464 KB Output is correct
28 Correct 3655 ms 17368 KB Output is correct
29 Correct 3858 ms 17416 KB Output is correct
30 Correct 3854 ms 17380 KB Output is correct
31 Correct 3934 ms 17400 KB Output is correct
32 Correct 3825 ms 17340 KB Output is correct
33 Correct 3970 ms 17000 KB Output is correct
34 Correct 3889 ms 17248 KB Output is correct
35 Correct 4085 ms 17160 KB Output is correct
36 Correct 3936 ms 18788 KB Output is correct
37 Correct 3788 ms 18796 KB Output is correct
38 Correct 3774 ms 18768 KB Output is correct
39 Correct 4037 ms 18756 KB Output is correct
40 Correct 3844 ms 18652 KB Output is correct
41 Correct 3735 ms 18628 KB Output is correct
42 Correct 3935 ms 18856 KB Output is correct
43 Correct 3688 ms 18796 KB Output is correct
44 Correct 3668 ms 18780 KB Output is correct
45 Correct 3885 ms 18688 KB Output is correct
46 Correct 3988 ms 18808 KB Output is correct
47 Correct 4062 ms 18800 KB Output is correct
48 Correct 3829 ms 18644 KB Output is correct
49 Correct 3888 ms 18460 KB Output is correct
50 Correct 3882 ms 18692 KB Output is correct