Submission #76359

# Submission time Handle Problem Language Result Execution time Memory
76359 2018-09-13T02:50:45 Z shoemakerjo Bali Sculptures (APIO15_sculpture) C++14
100 / 100
170 ms 1304 KB
#include <bits/stdc++.h>

using namespace std;
#define maxn 2010
const int inf = 123456789;
#define ll long long

int N, A, B;
ll nums[maxn];

ll pref = 0LL;
bool dp[maxn][maxn]; 
//is it possible to end at some guy using exactly some other amount
//use this dp table for N <= 100

//else we just want the minimum number
int mym[maxn]; 

bool check(ll bit) {
	fill(mym, mym+maxn, inf);
	mym[0] = 0;

	for (int i = 1; i <= N; i++) {
		ll csum = 0;
		for (int j = i; j >= 1; j--) {
			csum += nums[j];
			if ( (csum | pref) - pref >= bit) continue;
			mym[i] = min(mym[i], mym[j-1]+1);
		}
	}

	return mym[N] <= B;

}

void solve1() {
	for (int i = 50; i >= 0; i--) {
		ll cbit = 1LL << i;
		if (!check(cbit)) {
			pref += cbit;
		}
	}
	cout << pref << endl;
}

bool c2(ll bit) {

	for (int i = 0; i < 101; i++) {
		fill(dp[i], dp[i]+101, false);
	}

	dp[0][0] = true;

	for (int i = 1; i <= N; i++) {
		ll csum = 0LL;
		for (int j = i; j >= 1; j--) {
			csum += nums[j];
			if ((csum | pref) - pref >= bit) continue;
			for (int k = 0; k <= N; k++) {
				dp[i][k] |= dp[j-1][k-1];
			}
		}
	}


	for (int i = A; i <= B; i++) {
		if (dp[N][i]) return true;
	}
	return false;
}

void solve() {
	for (int i = 50; i >= 0; i--) {
		ll cbit = 1LL << i;
		if (!c2(cbit)) {
			pref += cbit;
		}
	}
	cout << pref << endl;
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N >> A >> B;
	for (int i = 1; i <= N; i++) {
		cin >> nums[i];

	}
	// solve();
	if (A == 1) solve1();
	else solve();

}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 540 KB Output is correct
7 Correct 2 ms 580 KB Output is correct
8 Correct 2 ms 580 KB Output is correct
9 Correct 2 ms 580 KB Output is correct
10 Correct 2 ms 580 KB Output is correct
11 Correct 2 ms 580 KB Output is correct
12 Correct 2 ms 580 KB Output is correct
13 Correct 2 ms 580 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
15 Correct 3 ms 716 KB Output is correct
16 Correct 3 ms 716 KB Output is correct
17 Correct 2 ms 796 KB Output is correct
18 Correct 3 ms 796 KB Output is correct
19 Correct 3 ms 796 KB Output is correct
20 Correct 3 ms 868 KB Output is correct
21 Correct 3 ms 956 KB Output is correct
22 Correct 3 ms 956 KB Output is correct
23 Correct 2 ms 956 KB Output is correct
24 Correct 3 ms 956 KB Output is correct
25 Correct 2 ms 956 KB Output is correct
26 Correct 3 ms 956 KB Output is correct
27 Correct 2 ms 956 KB Output is correct
28 Correct 2 ms 956 KB Output is correct
29 Correct 2 ms 956 KB Output is correct
30 Correct 2 ms 956 KB Output is correct
31 Correct 2 ms 956 KB Output is correct
32 Correct 2 ms 956 KB Output is correct
33 Correct 2 ms 956 KB Output is correct
34 Correct 2 ms 956 KB Output is correct
35 Correct 2 ms 956 KB Output is correct
36 Correct 2 ms 956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 956 KB Output is correct
2 Correct 2 ms 956 KB Output is correct
3 Correct 2 ms 956 KB Output is correct
4 Correct 2 ms 956 KB Output is correct
5 Correct 2 ms 956 KB Output is correct
6 Correct 2 ms 956 KB Output is correct
7 Correct 2 ms 956 KB Output is correct
8 Correct 2 ms 956 KB Output is correct
9 Correct 2 ms 956 KB Output is correct
10 Correct 2 ms 956 KB Output is correct
11 Correct 2 ms 956 KB Output is correct
12 Correct 2 ms 956 KB Output is correct
13 Correct 2 ms 956 KB Output is correct
14 Correct 3 ms 956 KB Output is correct
15 Correct 3 ms 956 KB Output is correct
16 Correct 2 ms 988 KB Output is correct
17 Correct 3 ms 988 KB Output is correct
18 Correct 3 ms 988 KB Output is correct
19 Correct 3 ms 988 KB Output is correct
20 Correct 3 ms 988 KB Output is correct
21 Correct 2 ms 988 KB Output is correct
22 Correct 3 ms 988 KB Output is correct
23 Correct 3 ms 988 KB Output is correct
24 Correct 3 ms 988 KB Output is correct
25 Correct 3 ms 1032 KB Output is correct
26 Correct 3 ms 1032 KB Output is correct
27 Correct 2 ms 1032 KB Output is correct
28 Correct 2 ms 1032 KB Output is correct
29 Correct 2 ms 1032 KB Output is correct
30 Correct 2 ms 1032 KB Output is correct
31 Correct 2 ms 1032 KB Output is correct
32 Correct 2 ms 1032 KB Output is correct
33 Correct 2 ms 1032 KB Output is correct
34 Correct 2 ms 1032 KB Output is correct
35 Correct 2 ms 1032 KB Output is correct
36 Correct 2 ms 1032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1032 KB Output is correct
2 Correct 2 ms 1032 KB Output is correct
3 Correct 2 ms 1032 KB Output is correct
4 Correct 2 ms 1032 KB Output is correct
5 Correct 2 ms 1032 KB Output is correct
6 Correct 2 ms 1032 KB Output is correct
7 Correct 2 ms 1032 KB Output is correct
8 Correct 3 ms 1032 KB Output is correct
9 Correct 2 ms 1032 KB Output is correct
10 Correct 2 ms 1032 KB Output is correct
11 Correct 2 ms 1032 KB Output is correct
12 Correct 2 ms 1032 KB Output is correct
13 Correct 2 ms 1032 KB Output is correct
14 Correct 2 ms 1032 KB Output is correct
15 Correct 2 ms 1032 KB Output is correct
16 Correct 2 ms 1032 KB Output is correct
17 Correct 2 ms 1032 KB Output is correct
18 Correct 2 ms 1032 KB Output is correct
19 Correct 2 ms 1032 KB Output is correct
20 Correct 2 ms 1032 KB Output is correct
21 Correct 2 ms 1032 KB Output is correct
22 Correct 2 ms 1032 KB Output is correct
23 Correct 2 ms 1032 KB Output is correct
24 Correct 2 ms 1032 KB Output is correct
25 Correct 2 ms 1032 KB Output is correct
26 Correct 3 ms 1032 KB Output is correct
27 Correct 3 ms 1032 KB Output is correct
28 Correct 3 ms 1032 KB Output is correct
29 Correct 3 ms 1032 KB Output is correct
30 Correct 3 ms 1032 KB Output is correct
31 Correct 3 ms 1032 KB Output is correct
32 Correct 3 ms 1032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1032 KB Output is correct
2 Correct 2 ms 1032 KB Output is correct
3 Correct 2 ms 1032 KB Output is correct
4 Correct 2 ms 1032 KB Output is correct
5 Correct 2 ms 1032 KB Output is correct
6 Correct 2 ms 1032 KB Output is correct
7 Correct 2 ms 1032 KB Output is correct
8 Correct 2 ms 1032 KB Output is correct
9 Correct 2 ms 1032 KB Output is correct
10 Correct 2 ms 1032 KB Output is correct
11 Correct 2 ms 1032 KB Output is correct
12 Correct 2 ms 1032 KB Output is correct
13 Correct 2 ms 1032 KB Output is correct
14 Correct 2 ms 1040 KB Output is correct
15 Correct 2 ms 1040 KB Output is correct
16 Correct 2 ms 1076 KB Output is correct
17 Correct 2 ms 1076 KB Output is correct
18 Correct 3 ms 1076 KB Output is correct
19 Correct 2 ms 1092 KB Output is correct
20 Correct 3 ms 1092 KB Output is correct
21 Correct 3 ms 1092 KB Output is correct
22 Correct 3 ms 1092 KB Output is correct
23 Correct 2 ms 1092 KB Output is correct
24 Correct 3 ms 1092 KB Output is correct
25 Correct 3 ms 1092 KB Output is correct
26 Correct 3 ms 1092 KB Output is correct
27 Correct 2 ms 1092 KB Output is correct
28 Correct 2 ms 1092 KB Output is correct
29 Correct 2 ms 1092 KB Output is correct
30 Correct 2 ms 1092 KB Output is correct
31 Correct 2 ms 1092 KB Output is correct
32 Correct 2 ms 1092 KB Output is correct
33 Correct 2 ms 1092 KB Output is correct
34 Correct 2 ms 1092 KB Output is correct
35 Correct 2 ms 1092 KB Output is correct
36 Correct 2 ms 1092 KB Output is correct
37 Correct 2 ms 1092 KB Output is correct
38 Correct 2 ms 1092 KB Output is correct
39 Correct 2 ms 1092 KB Output is correct
40 Correct 2 ms 1092 KB Output is correct
41 Correct 2 ms 1092 KB Output is correct
42 Correct 2 ms 1092 KB Output is correct
43 Correct 2 ms 1092 KB Output is correct
44 Correct 2 ms 1092 KB Output is correct
45 Correct 2 ms 1092 KB Output is correct
46 Correct 2 ms 1092 KB Output is correct
47 Correct 2 ms 1092 KB Output is correct
48 Correct 2 ms 1092 KB Output is correct
49 Correct 3 ms 1092 KB Output is correct
50 Correct 3 ms 1092 KB Output is correct
51 Correct 3 ms 1092 KB Output is correct
52 Correct 3 ms 1092 KB Output is correct
53 Correct 3 ms 1092 KB Output is correct
54 Correct 3 ms 1092 KB Output is correct
55 Correct 3 ms 1092 KB Output is correct
56 Correct 2 ms 1092 KB Output is correct
57 Correct 3 ms 1092 KB Output is correct
58 Correct 3 ms 1092 KB Output is correct
59 Correct 3 ms 1168 KB Output is correct
60 Correct 3 ms 1168 KB Output is correct
61 Correct 3 ms 1168 KB Output is correct
62 Correct 3 ms 1168 KB Output is correct
63 Correct 3 ms 1212 KB Output is correct
64 Correct 24 ms 1248 KB Output is correct
65 Correct 4 ms 1252 KB Output is correct
66 Correct 6 ms 1296 KB Output is correct
67 Correct 7 ms 1296 KB Output is correct
68 Correct 12 ms 1296 KB Output is correct
69 Correct 11 ms 1304 KB Output is correct
70 Correct 11 ms 1304 KB Output is correct
71 Correct 11 ms 1304 KB Output is correct
72 Correct 13 ms 1304 KB Output is correct
73 Correct 14 ms 1304 KB Output is correct
74 Correct 13 ms 1304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1304 KB Output is correct
2 Correct 2 ms 1304 KB Output is correct
3 Correct 2 ms 1304 KB Output is correct
4 Correct 2 ms 1304 KB Output is correct
5 Correct 2 ms 1304 KB Output is correct
6 Correct 2 ms 1304 KB Output is correct
7 Correct 3 ms 1304 KB Output is correct
8 Correct 2 ms 1304 KB Output is correct
9 Correct 2 ms 1304 KB Output is correct
10 Correct 2 ms 1304 KB Output is correct
11 Correct 2 ms 1304 KB Output is correct
12 Correct 2 ms 1304 KB Output is correct
13 Correct 2 ms 1304 KB Output is correct
14 Correct 2 ms 1304 KB Output is correct
15 Correct 2 ms 1304 KB Output is correct
16 Correct 2 ms 1304 KB Output is correct
17 Correct 2 ms 1304 KB Output is correct
18 Correct 2 ms 1304 KB Output is correct
19 Correct 2 ms 1304 KB Output is correct
20 Correct 2 ms 1304 KB Output is correct
21 Correct 2 ms 1304 KB Output is correct
22 Correct 2 ms 1304 KB Output is correct
23 Correct 2 ms 1304 KB Output is correct
24 Correct 2 ms 1304 KB Output is correct
25 Correct 2 ms 1304 KB Output is correct
26 Correct 2 ms 1304 KB Output is correct
27 Correct 3 ms 1304 KB Output is correct
28 Correct 2 ms 1304 KB Output is correct
29 Correct 2 ms 1304 KB Output is correct
30 Correct 2 ms 1304 KB Output is correct
31 Correct 2 ms 1304 KB Output is correct
32 Correct 2 ms 1304 KB Output is correct
33 Correct 2 ms 1304 KB Output is correct
34 Correct 2 ms 1304 KB Output is correct
35 Correct 2 ms 1304 KB Output is correct
36 Correct 3 ms 1304 KB Output is correct
37 Correct 3 ms 1304 KB Output is correct
38 Correct 3 ms 1304 KB Output is correct
39 Correct 3 ms 1304 KB Output is correct
40 Correct 3 ms 1304 KB Output is correct
41 Correct 3 ms 1304 KB Output is correct
42 Correct 3 ms 1304 KB Output is correct
43 Correct 2 ms 1304 KB Output is correct
44 Correct 2 ms 1304 KB Output is correct
45 Correct 3 ms 1304 KB Output is correct
46 Correct 3 ms 1304 KB Output is correct
47 Correct 2 ms 1304 KB Output is correct
48 Correct 3 ms 1304 KB Output is correct
49 Correct 3 ms 1304 KB Output is correct
50 Correct 3 ms 1304 KB Output is correct
51 Correct 3 ms 1304 KB Output is correct
52 Correct 16 ms 1304 KB Output is correct
53 Correct 25 ms 1304 KB Output is correct
54 Correct 46 ms 1304 KB Output is correct
55 Correct 42 ms 1304 KB Output is correct
56 Correct 154 ms 1304 KB Output is correct
57 Correct 155 ms 1304 KB Output is correct
58 Correct 157 ms 1304 KB Output is correct
59 Correct 154 ms 1304 KB Output is correct
60 Correct 159 ms 1304 KB Output is correct
61 Correct 3 ms 1304 KB Output is correct
62 Correct 25 ms 1304 KB Output is correct
63 Correct 47 ms 1304 KB Output is correct
64 Correct 44 ms 1304 KB Output is correct
65 Correct 81 ms 1304 KB Output is correct
66 Correct 120 ms 1304 KB Output is correct
67 Correct 159 ms 1304 KB Output is correct
68 Correct 167 ms 1304 KB Output is correct
69 Correct 170 ms 1304 KB Output is correct