Submission #46578

# Submission time Handle Problem Language Result Execution time Memory
46578 2018-04-21T14:29:04 Z aome Bali Sculptures (APIO15_sculpture) C++17
100 / 100
136 ms 2448 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2005;

int n, A, B;
int arr[N];
long long sum[N];

namespace Task1 {

	bool f[N][N];

	void calDP(long long mask) {
		f[0][0] = 1;
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= i; ++j) {
				f[i][j] = 0;
			}
		}
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= i; ++j) {
				for (int k = 0; k < i; ++k) {
					if ((sum[i] - sum[k]) & mask) continue;
					f[i][j] |= f[k][j - 1]; 
				}
			}
		}
	}

	void solve() {
		long long mask = 0, res = 0;
		for (int i = 45; i >= 0; --i) {
			mask ^= (1LL << i);
			calDP(mask);
			bool found = 0;
			for (int j = A; j <= B; ++j) found |= f[n][j];
			if (!found) {
				mask ^= (1LL << i), res += 1LL << i;
			}
		}
		cout << res;
	}
}

namespace Task2 {
	const int INF = 1e9;

	int f[N];

	void calDP(long long mask) {
		f[0] = 0;
		for (int i = 1; i <= n; ++i) {
			f[i] = INF;
			for (int j = 0; j < i; ++j) {
				if ((sum[i] - sum[j]) & mask) continue;
				f[i] = min(f[i], f[j] + 1);
			}
		}
	}

	void solve() {
		long long mask = 0, res = 0;
		for (int i = 45; i >= 0; --i) {
			mask ^= (1LL << i);
			calDP(mask);
			bool found = f[n] <= B;
			if (!found) {
				mask ^= (1LL << i), res += 1LL << i;
			}			
		}
		cout << res << '\n';
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> A >> B;
	for (int i = 1; i <= n; ++i) cin >> arr[i];
	for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + arr[i];
	if (n <= 100) 
		Task1::solve();
	else 
		Task2::solve();
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 496 KB Output is correct
3 Correct 3 ms 568 KB Output is correct
4 Correct 2 ms 568 KB Output is correct
5 Correct 2 ms 568 KB Output is correct
6 Correct 2 ms 676 KB Output is correct
7 Correct 2 ms 676 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
9 Correct 2 ms 676 KB Output is correct
10 Correct 2 ms 728 KB Output is correct
11 Correct 2 ms 728 KB Output is correct
12 Correct 2 ms 728 KB Output is correct
13 Correct 3 ms 728 KB Output is correct
14 Correct 2 ms 728 KB Output is correct
15 Correct 2 ms 728 KB Output is correct
16 Correct 2 ms 728 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Correct 2 ms 852 KB Output is correct
19 Correct 2 ms 852 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 3 ms 852 KB Output is correct
22 Correct 2 ms 928 KB Output is correct
23 Correct 2 ms 928 KB Output is correct
24 Correct 2 ms 928 KB Output is correct
25 Correct 2 ms 928 KB Output is correct
26 Correct 2 ms 928 KB Output is correct
27 Correct 2 ms 928 KB Output is correct
28 Correct 2 ms 928 KB Output is correct
29 Correct 3 ms 928 KB Output is correct
30 Correct 2 ms 928 KB Output is correct
31 Correct 2 ms 928 KB Output is correct
32 Correct 2 ms 928 KB Output is correct
33 Correct 2 ms 928 KB Output is correct
34 Correct 2 ms 928 KB Output is correct
35 Correct 2 ms 928 KB Output is correct
36 Correct 3 ms 928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 928 KB Output is correct
2 Correct 2 ms 928 KB Output is correct
3 Correct 2 ms 928 KB Output is correct
4 Correct 2 ms 928 KB Output is correct
5 Correct 2 ms 928 KB Output is correct
6 Correct 2 ms 928 KB Output is correct
7 Correct 2 ms 928 KB Output is correct
8 Correct 2 ms 928 KB Output is correct
9 Correct 2 ms 928 KB Output is correct
10 Correct 2 ms 928 KB Output is correct
11 Correct 2 ms 928 KB Output is correct
12 Correct 2 ms 928 KB Output is correct
13 Correct 2 ms 932 KB Output is correct
14 Correct 2 ms 936 KB Output is correct
15 Correct 2 ms 940 KB Output is correct
16 Correct 2 ms 944 KB Output is correct
17 Correct 3 ms 1036 KB Output is correct
18 Correct 2 ms 1036 KB Output is correct
19 Correct 2 ms 1036 KB Output is correct
20 Correct 2 ms 1036 KB Output is correct
21 Correct 2 ms 1064 KB Output is correct
22 Correct 3 ms 1064 KB Output is correct
23 Correct 2 ms 1064 KB Output is correct
24 Correct 2 ms 1064 KB Output is correct
25 Correct 3 ms 1064 KB Output is correct
26 Correct 2 ms 1064 KB Output is correct
27 Correct 2 ms 1064 KB Output is correct
28 Correct 3 ms 1064 KB Output is correct
29 Correct 4 ms 1076 KB Output is correct
30 Correct 5 ms 1136 KB Output is correct
31 Correct 7 ms 1160 KB Output is correct
32 Correct 6 ms 1164 KB Output is correct
33 Correct 6 ms 1164 KB Output is correct
34 Correct 6 ms 1164 KB Output is correct
35 Correct 6 ms 1164 KB Output is correct
36 Correct 6 ms 1164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1164 KB Output is correct
2 Correct 2 ms 1164 KB Output is correct
3 Correct 2 ms 1164 KB Output is correct
4 Correct 2 ms 1164 KB Output is correct
5 Correct 2 ms 1164 KB Output is correct
6 Correct 2 ms 1164 KB Output is correct
7 Correct 2 ms 1164 KB Output is correct
8 Correct 2 ms 1164 KB Output is correct
9 Correct 3 ms 1164 KB Output is correct
10 Correct 2 ms 1164 KB Output is correct
11 Correct 3 ms 1164 KB Output is correct
12 Correct 3 ms 1164 KB Output is correct
13 Correct 2 ms 1164 KB Output is correct
14 Correct 2 ms 1164 KB Output is correct
15 Correct 2 ms 1164 KB Output is correct
16 Correct 4 ms 1252 KB Output is correct
17 Correct 6 ms 1252 KB Output is correct
18 Correct 6 ms 1292 KB Output is correct
19 Correct 8 ms 1296 KB Output is correct
20 Correct 7 ms 1296 KB Output is correct
21 Correct 6 ms 1304 KB Output is correct
22 Correct 7 ms 1304 KB Output is correct
23 Correct 8 ms 1304 KB Output is correct
24 Correct 6 ms 1304 KB Output is correct
25 Correct 11 ms 1324 KB Output is correct
26 Correct 22 ms 1328 KB Output is correct
27 Correct 27 ms 1408 KB Output is correct
28 Correct 35 ms 1464 KB Output is correct
29 Correct 34 ms 1508 KB Output is correct
30 Correct 35 ms 1508 KB Output is correct
31 Correct 39 ms 1508 KB Output is correct
32 Correct 35 ms 1508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1508 KB Output is correct
2 Correct 2 ms 1508 KB Output is correct
3 Correct 2 ms 1508 KB Output is correct
4 Correct 2 ms 1508 KB Output is correct
5 Correct 2 ms 1508 KB Output is correct
6 Correct 2 ms 1508 KB Output is correct
7 Correct 2 ms 1508 KB Output is correct
8 Correct 2 ms 1508 KB Output is correct
9 Correct 2 ms 1508 KB Output is correct
10 Correct 2 ms 1508 KB Output is correct
11 Correct 2 ms 1508 KB Output is correct
12 Correct 2 ms 1508 KB Output is correct
13 Correct 2 ms 1508 KB Output is correct
14 Correct 2 ms 1508 KB Output is correct
15 Correct 2 ms 1508 KB Output is correct
16 Correct 2 ms 1508 KB Output is correct
17 Correct 2 ms 1508 KB Output is correct
18 Correct 2 ms 1508 KB Output is correct
19 Correct 2 ms 1508 KB Output is correct
20 Correct 2 ms 1508 KB Output is correct
21 Correct 2 ms 1508 KB Output is correct
22 Correct 2 ms 1508 KB Output is correct
23 Correct 2 ms 1508 KB Output is correct
24 Correct 2 ms 1508 KB Output is correct
25 Correct 2 ms 1508 KB Output is correct
26 Correct 2 ms 1508 KB Output is correct
27 Correct 2 ms 1508 KB Output is correct
28 Correct 2 ms 1508 KB Output is correct
29 Correct 2 ms 1508 KB Output is correct
30 Correct 3 ms 1508 KB Output is correct
31 Correct 2 ms 1508 KB Output is correct
32 Correct 2 ms 1508 KB Output is correct
33 Correct 2 ms 1508 KB Output is correct
34 Correct 2 ms 1508 KB Output is correct
35 Correct 2 ms 1508 KB Output is correct
36 Correct 2 ms 1568 KB Output is correct
37 Correct 2 ms 1568 KB Output is correct
38 Correct 2 ms 1568 KB Output is correct
39 Correct 4 ms 1568 KB Output is correct
40 Correct 4 ms 1568 KB Output is correct
41 Correct 6 ms 1568 KB Output is correct
42 Correct 6 ms 1568 KB Output is correct
43 Correct 6 ms 1568 KB Output is correct
44 Correct 7 ms 1568 KB Output is correct
45 Correct 6 ms 1568 KB Output is correct
46 Correct 6 ms 1576 KB Output is correct
47 Correct 6 ms 1580 KB Output is correct
48 Correct 13 ms 1584 KB Output is correct
49 Correct 17 ms 1592 KB Output is correct
50 Correct 26 ms 1592 KB Output is correct
51 Correct 35 ms 1596 KB Output is correct
52 Correct 36 ms 1692 KB Output is correct
53 Correct 47 ms 1692 KB Output is correct
54 Correct 35 ms 1692 KB Output is correct
55 Correct 35 ms 1708 KB Output is correct
56 Correct 5 ms 1708 KB Output is correct
57 Correct 17 ms 1748 KB Output is correct
58 Correct 25 ms 1748 KB Output is correct
59 Correct 23 ms 1748 KB Output is correct
60 Correct 26 ms 1748 KB Output is correct
61 Correct 31 ms 1748 KB Output is correct
62 Correct 25 ms 1788 KB Output is correct
63 Correct 25 ms 1788 KB Output is correct
64 Correct 27 ms 1788 KB Output is correct
65 Correct 5 ms 1788 KB Output is correct
66 Correct 11 ms 1788 KB Output is correct
67 Correct 13 ms 1788 KB Output is correct
68 Correct 19 ms 1788 KB Output is correct
69 Correct 28 ms 1788 KB Output is correct
70 Correct 31 ms 1788 KB Output is correct
71 Correct 28 ms 1788 KB Output is correct
72 Correct 25 ms 1788 KB Output is correct
73 Correct 26 ms 1788 KB Output is correct
74 Correct 30 ms 1824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1824 KB Output is correct
2 Correct 2 ms 1824 KB Output is correct
3 Correct 2 ms 1824 KB Output is correct
4 Correct 2 ms 1824 KB Output is correct
5 Correct 2 ms 1824 KB Output is correct
6 Correct 2 ms 1824 KB Output is correct
7 Correct 2 ms 1824 KB Output is correct
8 Correct 2 ms 1824 KB Output is correct
9 Correct 2 ms 1824 KB Output is correct
10 Correct 2 ms 1824 KB Output is correct
11 Correct 2 ms 1824 KB Output is correct
12 Correct 2 ms 1824 KB Output is correct
13 Correct 2 ms 1824 KB Output is correct
14 Correct 2 ms 1824 KB Output is correct
15 Correct 2 ms 1824 KB Output is correct
16 Correct 3 ms 1824 KB Output is correct
17 Correct 3 ms 1828 KB Output is correct
18 Correct 2 ms 1828 KB Output is correct
19 Correct 2 ms 1828 KB Output is correct
20 Correct 2 ms 1828 KB Output is correct
21 Correct 2 ms 1836 KB Output is correct
22 Correct 2 ms 1836 KB Output is correct
23 Correct 2 ms 1840 KB Output is correct
24 Correct 2 ms 1844 KB Output is correct
25 Correct 3 ms 1848 KB Output is correct
26 Correct 4 ms 1864 KB Output is correct
27 Correct 5 ms 1864 KB Output is correct
28 Correct 6 ms 1988 KB Output is correct
29 Correct 6 ms 2024 KB Output is correct
30 Correct 6 ms 2024 KB Output is correct
31 Correct 6 ms 2024 KB Output is correct
32 Correct 6 ms 2024 KB Output is correct
33 Correct 6 ms 2024 KB Output is correct
34 Correct 6 ms 2024 KB Output is correct
35 Correct 15 ms 2048 KB Output is correct
36 Correct 17 ms 2104 KB Output is correct
37 Correct 34 ms 2104 KB Output is correct
38 Correct 36 ms 2152 KB Output is correct
39 Correct 43 ms 2152 KB Output is correct
40 Correct 45 ms 2152 KB Output is correct
41 Correct 35 ms 2152 KB Output is correct
42 Correct 35 ms 2152 KB Output is correct
43 Correct 5 ms 2152 KB Output is correct
44 Correct 12 ms 2152 KB Output is correct
45 Correct 18 ms 2152 KB Output is correct
46 Correct 23 ms 2152 KB Output is correct
47 Correct 23 ms 2264 KB Output is correct
48 Correct 23 ms 2264 KB Output is correct
49 Correct 26 ms 2264 KB Output is correct
50 Correct 27 ms 2264 KB Output is correct
51 Correct 2 ms 2264 KB Output is correct
52 Correct 13 ms 2264 KB Output is correct
53 Correct 22 ms 2264 KB Output is correct
54 Correct 40 ms 2264 KB Output is correct
55 Correct 37 ms 2264 KB Output is correct
56 Correct 123 ms 2264 KB Output is correct
57 Correct 122 ms 2264 KB Output is correct
58 Correct 117 ms 2264 KB Output is correct
59 Correct 126 ms 2264 KB Output is correct
60 Correct 136 ms 2264 KB Output is correct
61 Correct 2 ms 2264 KB Output is correct
62 Correct 20 ms 2264 KB Output is correct
63 Correct 44 ms 2264 KB Output is correct
64 Correct 33 ms 2264 KB Output is correct
65 Correct 67 ms 2264 KB Output is correct
66 Correct 91 ms 2284 KB Output is correct
67 Correct 120 ms 2284 KB Output is correct
68 Correct 122 ms 2284 KB Output is correct
69 Correct 120 ms 2448 KB Output is correct