Submission #40948

# Submission time Handle Problem Language Result Execution time Memory
40948 2018-02-09T23:47:40 Z IvanC Bali Sculptures (APIO15_sculpture) C++14
75 / 100
1000 ms 876 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2010;
const int MAXM = 110;
int dp[MAXN],N,A,B;
bool tab[MAXM][MAXM],possivel;
ll soma[MAXN],proibido,atual;
ll calc(ll a,ll b){return soma[b] - soma[a-1];}
int solve(int pos){
	if(dp[pos] != -1) return dp[pos];
	if(pos == N + 1) return dp[pos] = 0;
	int best = MAXN;
	for(int quebra = pos;quebra<=N;quebra++){
		if((calc(pos,quebra)) & proibido) continue;
		best = min(best, 1 + solve(quebra+1));
	}
	return dp[pos] = best;
}
void check(int pos,int resta){
	if(tab[pos][resta]) return;
	if(pos == N + 1 && resta == 0) possivel = true;
	if(resta == 0) return;
	for(int quebra = pos;quebra<=N;quebra++){
		if((calc(pos,quebra)) & proibido) continue;
		check(quebra+1,resta - 1);
	}
}
int main(){
	cin >> N >> A >> B;
	if(A == 1){
		for(int i = 1;i<=N;i++){
			cin >> soma[i];
			soma[i] += soma[i-1];
		}
		for(ll i = 41;i>=0;i--){
			proibido |= (1LL << i);
			memset(dp,-1,sizeof(dp));
			if(solve(1) > B){
				proibido ^= (1LL << i);
				atual |= (1LL << i);
			}
		}
		cout << atual << endl;
	}
	else{
		for(int i = 1;i<=N;i++){
			cin >> soma[i];
			soma[i] += soma[i-1];
		}
		for(ll i = 41;i>=0;i--){
			proibido |= (1LL << i);
			memset(tab,false,sizeof(tab));
			possivel = false;
			for(int j = A;j<=B;j++) check(1,j);
			if(!possivel){
				proibido ^= (1LL << i);
				atual |= (1LL << i);
			}
		}
		cout << atual << endl;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 1 ms 428 KB Output is correct
4 Correct 2 ms 580 KB Output is correct
5 Correct 1 ms 628 KB Output is correct
6 Correct 2 ms 628 KB Output is correct
7 Correct 2 ms 668 KB Output is correct
8 Correct 2 ms 680 KB Output is correct
9 Correct 1 ms 680 KB Output is correct
10 Correct 1 ms 680 KB Output is correct
11 Correct 2 ms 680 KB Output is correct
12 Correct 1 ms 680 KB Output is correct
13 Correct 2 ms 680 KB Output is correct
14 Correct 1 ms 680 KB Output is correct
15 Correct 2 ms 680 KB Output is correct
16 Correct 2 ms 680 KB Output is correct
17 Correct 1 ms 680 KB Output is correct
18 Correct 2 ms 680 KB Output is correct
19 Correct 9 ms 680 KB Output is correct
20 Correct 2 ms 680 KB Output is correct
21 Correct 50 ms 680 KB Output is correct
22 Correct 44 ms 748 KB Output is correct
23 Correct 44 ms 748 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 48 ms 748 KB Output is correct
26 Correct 997 ms 748 KB Output is correct
27 Correct 1 ms 748 KB Output is correct
28 Correct 2 ms 748 KB Output is correct
29 Correct 1 ms 748 KB Output is correct
30 Correct 2 ms 748 KB Output is correct
31 Correct 2 ms 748 KB Output is correct
32 Correct 2 ms 748 KB Output is correct
33 Correct 1 ms 748 KB Output is correct
34 Correct 2 ms 748 KB Output is correct
35 Correct 2 ms 748 KB Output is correct
36 Correct 2 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
4 Correct 1 ms 748 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 2 ms 748 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 2 ms 748 KB Output is correct
9 Correct 2 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 1 ms 748 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 2 ms 748 KB Output is correct
17 Correct 2 ms 748 KB Output is correct
18 Correct 2 ms 748 KB Output is correct
19 Correct 10 ms 748 KB Output is correct
20 Correct 2 ms 748 KB Output is correct
21 Correct 46 ms 748 KB Output is correct
22 Correct 46 ms 748 KB Output is correct
23 Correct 44 ms 748 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 72 ms 748 KB Output is correct
26 Correct 999 ms 748 KB Output is correct
27 Correct 2 ms 748 KB Output is correct
28 Correct 9 ms 748 KB Output is correct
29 Correct 2 ms 748 KB Output is correct
30 Correct 2 ms 748 KB Output is correct
31 Correct 2 ms 748 KB Output is correct
32 Correct 2 ms 748 KB Output is correct
33 Correct 2 ms 748 KB Output is correct
34 Correct 2 ms 748 KB Output is correct
35 Correct 2 ms 748 KB Output is correct
36 Correct 2 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
4 Correct 1 ms 748 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 2 ms 748 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 2 ms 748 KB Output is correct
9 Correct 2 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 2 ms 748 KB Output is correct
12 Correct 2 ms 748 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
16 Correct 2 ms 748 KB Output is correct
17 Correct 2 ms 748 KB Output is correct
18 Correct 2 ms 748 KB Output is correct
19 Correct 2 ms 748 KB Output is correct
20 Correct 2 ms 748 KB Output is correct
21 Correct 2 ms 748 KB Output is correct
22 Correct 2 ms 748 KB Output is correct
23 Correct 2 ms 748 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 3 ms 748 KB Output is correct
27 Correct 2 ms 748 KB Output is correct
28 Correct 3 ms 748 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
30 Correct 3 ms 748 KB Output is correct
31 Correct 2 ms 748 KB Output is correct
32 Correct 2 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 2 ms 748 KB Output is correct
6 Correct 2 ms 748 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 2 ms 748 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 1 ms 748 KB Output is correct
11 Correct 2 ms 748 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 748 KB Output is correct
17 Correct 1 ms 748 KB Output is correct
18 Correct 1 ms 748 KB Output is correct
19 Correct 9 ms 748 KB Output is correct
20 Correct 1 ms 748 KB Output is correct
21 Correct 52 ms 748 KB Output is correct
22 Correct 42 ms 748 KB Output is correct
23 Correct 43 ms 748 KB Output is correct
24 Correct 1 ms 748 KB Output is correct
25 Correct 46 ms 748 KB Output is correct
26 Execution timed out 1016 ms 748 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 748 KB Output is correct
2 Correct 1 ms 748 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 2 ms 748 KB Output is correct
6 Correct 2 ms 748 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 2 ms 748 KB Output is correct
12 Correct 2 ms 748 KB Output is correct
13 Correct 1 ms 748 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 748 KB Output is correct
17 Correct 1 ms 748 KB Output is correct
18 Correct 1 ms 748 KB Output is correct
19 Correct 1 ms 748 KB Output is correct
20 Correct 1 ms 748 KB Output is correct
21 Correct 1 ms 748 KB Output is correct
22 Correct 2 ms 748 KB Output is correct
23 Correct 1 ms 748 KB Output is correct
24 Correct 1 ms 748 KB Output is correct
25 Correct 1 ms 748 KB Output is correct
26 Correct 1 ms 748 KB Output is correct
27 Correct 2 ms 748 KB Output is correct
28 Correct 2 ms 748 KB Output is correct
29 Correct 2 ms 748 KB Output is correct
30 Correct 2 ms 748 KB Output is correct
31 Correct 2 ms 748 KB Output is correct
32 Correct 2 ms 748 KB Output is correct
33 Correct 2 ms 748 KB Output is correct
34 Correct 2 ms 748 KB Output is correct
35 Correct 2 ms 748 KB Output is correct
36 Correct 3 ms 748 KB Output is correct
37 Correct 2 ms 748 KB Output is correct
38 Correct 2 ms 748 KB Output is correct
39 Correct 3 ms 748 KB Output is correct
40 Correct 2 ms 748 KB Output is correct
41 Correct 3 ms 748 KB Output is correct
42 Correct 2 ms 748 KB Output is correct
43 Correct 1 ms 748 KB Output is correct
44 Correct 2 ms 748 KB Output is correct
45 Correct 2 ms 748 KB Output is correct
46 Correct 2 ms 748 KB Output is correct
47 Correct 2 ms 748 KB Output is correct
48 Correct 2 ms 748 KB Output is correct
49 Correct 3 ms 748 KB Output is correct
50 Correct 2 ms 748 KB Output is correct
51 Correct 2 ms 748 KB Output is correct
52 Correct 10 ms 748 KB Output is correct
53 Correct 11 ms 748 KB Output is correct
54 Correct 35 ms 748 KB Output is correct
55 Correct 44 ms 748 KB Output is correct
56 Correct 61 ms 876 KB Output is correct
57 Correct 55 ms 876 KB Output is correct
58 Correct 61 ms 876 KB Output is correct
59 Correct 87 ms 876 KB Output is correct
60 Correct 71 ms 876 KB Output is correct
61 Correct 2 ms 876 KB Output is correct
62 Correct 17 ms 876 KB Output is correct
63 Correct 44 ms 876 KB Output is correct
64 Correct 29 ms 876 KB Output is correct
65 Correct 44 ms 876 KB Output is correct
66 Correct 59 ms 876 KB Output is correct
67 Correct 53 ms 876 KB Output is correct
68 Correct 136 ms 876 KB Output is correct
69 Correct 53 ms 876 KB Output is correct