답안 #854950

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854950 2023-09-29T12:38:40 Z QuangBui Cigle (COI21_cigle) C++14
100 / 100
87 ms 97532 KB
// QuangBuiCP
#ifndef LOCAL
#pragma GCC optimize(3)
#pragma GCC target("avx2")
#endif // LOCAL
#include "bits/stdc++.h"
using namespace std;

#define SZ(a) (int)(a).size()
#define ALL(a) (a).begin(),(a).end()

const int N = 5005;

int n;
int a[N];
int pref[N];
int dp[N][N];
int f[N];

int Brute() {
	int ret = 0;
	for (int mask = 0; mask < (1 << n); ++mask) {
		int cnt = 0;
		set<int> prv, cur;
		int pos = 0, layer = 0;
		bool no = false;
		for (int i = 1; i < n; ++i) {
			int x1 = 0, x2 = 0;
			if (mask >> i & 1) {
				x1 = 1;
			}
			if (mask >> (i - 1) & 1) {
				x2 = 1;
			}
			if (x1 && x2) {
				no = true;
				break;
			}
		}
		if (no) {
			continue;
		}
		for (int i = 0; i < n; ++i) {
			if (mask >> i & 1) {
				layer++;
				prv = cur;
				cur.clear();
			}
			int sign = 1;
			if (layer % 2) {
				sign *= -1;
			}
			pos += sign * a[i + 1];
			if (prv.count(pos) && i != n - 1 && !(mask >> (i + 1) & 1)) {
				cnt++;
			}
			cur.insert(pos);
		}
		ret = max(ret, cnt);
	}
	return ret;
}

signed main() {
#ifndef LOCAL
	cin.tie(nullptr)->sync_with_stdio(false);
#endif // LOCAL

	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		a[i] += a[i - 1];
	}
	// cout << Brute() << '\n';
	for (int j = 1; j <= n; ++j) {
		for (int i = 0; i < j; ++i) {
			f[i] = dp[i][j];
		}
		for (int i = 1; i < j; ++i) {
			f[i] = max(f[i], f[i - 1]);
		}
		int cur = 0, cnt = 0;
		for (int i = j - 1, k = j + 1; k <= n; ++k) {
			dp[j][k] = cur;
			while (i > 0 && a[i] + a[k] > a[j] * 2) {
				i--;
			}
			if (i > 0 && a[i] + a[k] == a[j] * 2) {
				cnt++;
				cur = max(cur, f[i - 1] + cnt);
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		ans = max(ans, dp[i][n]);
	}
	cout << ans << '\n';

#ifdef LOCAL
	cerr << '\n' << clock() << "ms.";
#endif // LOCAL
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2520 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2520 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10584 KB Output is correct
4 Correct 2 ms 10584 KB Output is correct
5 Correct 2 ms 10584 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 3 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10704 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2520 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 2 ms 10588 KB Output is correct
23 Correct 2 ms 10584 KB Output is correct
24 Correct 2 ms 10584 KB Output is correct
25 Correct 2 ms 10584 KB Output is correct
26 Correct 2 ms 10588 KB Output is correct
27 Correct 3 ms 10588 KB Output is correct
28 Correct 2 ms 10588 KB Output is correct
29 Correct 2 ms 10704 KB Output is correct
30 Correct 2 ms 10588 KB Output is correct
31 Correct 2 ms 10588 KB Output is correct
32 Correct 2 ms 10584 KB Output is correct
33 Correct 2 ms 10588 KB Output is correct
34 Correct 2 ms 10588 KB Output is correct
35 Correct 2 ms 10588 KB Output is correct
36 Correct 2 ms 10588 KB Output is correct
37 Correct 2 ms 10588 KB Output is correct
38 Correct 2 ms 10588 KB Output is correct
39 Correct 2 ms 10588 KB Output is correct
40 Correct 2 ms 10712 KB Output is correct
41 Correct 2 ms 10588 KB Output is correct
42 Correct 2 ms 10840 KB Output is correct
43 Correct 2 ms 10588 KB Output is correct
44 Correct 2 ms 10588 KB Output is correct
45 Correct 2 ms 10588 KB Output is correct
46 Correct 2 ms 10704 KB Output is correct
47 Correct 2 ms 10588 KB Output is correct
48 Correct 2 ms 10772 KB Output is correct
49 Correct 3 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2520 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 2 ms 10588 KB Output is correct
23 Correct 2 ms 10584 KB Output is correct
24 Correct 2 ms 10584 KB Output is correct
25 Correct 2 ms 10584 KB Output is correct
26 Correct 2 ms 10588 KB Output is correct
27 Correct 3 ms 10588 KB Output is correct
28 Correct 2 ms 10588 KB Output is correct
29 Correct 2 ms 10704 KB Output is correct
30 Correct 2 ms 10588 KB Output is correct
31 Correct 2 ms 10588 KB Output is correct
32 Correct 2 ms 10584 KB Output is correct
33 Correct 2 ms 10588 KB Output is correct
34 Correct 2 ms 10588 KB Output is correct
35 Correct 2 ms 10588 KB Output is correct
36 Correct 2 ms 10588 KB Output is correct
37 Correct 2 ms 10588 KB Output is correct
38 Correct 2 ms 10588 KB Output is correct
39 Correct 2 ms 10588 KB Output is correct
40 Correct 2 ms 10712 KB Output is correct
41 Correct 2 ms 10588 KB Output is correct
42 Correct 2 ms 10840 KB Output is correct
43 Correct 2 ms 10588 KB Output is correct
44 Correct 2 ms 10588 KB Output is correct
45 Correct 2 ms 10588 KB Output is correct
46 Correct 2 ms 10704 KB Output is correct
47 Correct 2 ms 10588 KB Output is correct
48 Correct 2 ms 10772 KB Output is correct
49 Correct 3 ms 10588 KB Output is correct
50 Correct 46 ms 97268 KB Output is correct
51 Correct 44 ms 97228 KB Output is correct
52 Correct 46 ms 97360 KB Output is correct
53 Correct 44 ms 97108 KB Output is correct
54 Correct 49 ms 97364 KB Output is correct
55 Correct 46 ms 97108 KB Output is correct
56 Correct 80 ms 97364 KB Output is correct
57 Correct 79 ms 97108 KB Output is correct
58 Correct 87 ms 97240 KB Output is correct
59 Correct 80 ms 97260 KB Output is correct
60 Correct 87 ms 97304 KB Output is correct
61 Correct 65 ms 97184 KB Output is correct
62 Correct 63 ms 97360 KB Output is correct
63 Correct 56 ms 97364 KB Output is correct
64 Correct 59 ms 97364 KB Output is correct
65 Correct 57 ms 97360 KB Output is correct
66 Correct 62 ms 97364 KB Output is correct
67 Correct 58 ms 97504 KB Output is correct
68 Correct 51 ms 97308 KB Output is correct
69 Correct 52 ms 97364 KB Output is correct
70 Correct 77 ms 97364 KB Output is correct
71 Correct 83 ms 97532 KB Output is correct
72 Correct 71 ms 97360 KB Output is correct