Submission #40949

# Submission time Handle Problem Language Result Execution time Memory
40949 2018-02-09T23:48:58 Z IvanC Bali Sculptures (APIO15_sculpture) C++14
75 / 100
1000 ms 1004 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(possivel) return;
	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 1 ms 248 KB Output is correct
2 Correct 1 ms 480 KB Output is correct
3 Correct 1 ms 480 KB Output is correct
4 Correct 1 ms 480 KB Output is correct
5 Correct 2 ms 480 KB Output is correct
6 Correct 3 ms 480 KB Output is correct
7 Correct 2 ms 500 KB Output is correct
8 Correct 2 ms 516 KB Output is correct
9 Correct 2 ms 516 KB Output is correct
10 Correct 1 ms 516 KB Output is correct
11 Correct 2 ms 516 KB Output is correct
12 Correct 2 ms 572 KB Output is correct
13 Correct 2 ms 608 KB Output is correct
14 Correct 2 ms 608 KB Output is correct
15 Correct 1 ms 608 KB Output is correct
16 Correct 1 ms 608 KB Output is correct
17 Correct 2 ms 608 KB Output is correct
18 Correct 1 ms 608 KB Output is correct
19 Correct 2 ms 620 KB Output is correct
20 Correct 1 ms 620 KB Output is correct
21 Correct 2 ms 620 KB Output is correct
22 Correct 2 ms 620 KB Output is correct
23 Correct 2 ms 620 KB Output is correct
24 Correct 2 ms 620 KB Output is correct
25 Correct 2 ms 620 KB Output is correct
26 Correct 2 ms 620 KB Output is correct
27 Correct 1 ms 620 KB Output is correct
28 Correct 2 ms 620 KB Output is correct
29 Correct 2 ms 620 KB Output is correct
30 Correct 2 ms 620 KB Output is correct
31 Correct 2 ms 620 KB Output is correct
32 Correct 2 ms 620 KB Output is correct
33 Correct 2 ms 624 KB Output is correct
34 Correct 2 ms 624 KB Output is correct
35 Correct 2 ms 624 KB Output is correct
36 Correct 2 ms 624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 624 KB Output is correct
2 Correct 2 ms 624 KB Output is correct
3 Correct 1 ms 624 KB Output is correct
4 Correct 2 ms 624 KB Output is correct
5 Correct 1 ms 624 KB Output is correct
6 Correct 2 ms 624 KB Output is correct
7 Correct 2 ms 624 KB Output is correct
8 Correct 2 ms 624 KB Output is correct
9 Correct 2 ms 624 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 2 ms 624 KB Output is correct
12 Correct 2 ms 624 KB Output is correct
13 Correct 2 ms 624 KB Output is correct
14 Correct 2 ms 744 KB Output is correct
15 Correct 1 ms 744 KB Output is correct
16 Correct 2 ms 744 KB Output is correct
17 Correct 2 ms 744 KB Output is correct
18 Correct 2 ms 744 KB Output is correct
19 Correct 2 ms 744 KB Output is correct
20 Correct 2 ms 744 KB Output is correct
21 Correct 2 ms 744 KB Output is correct
22 Correct 2 ms 744 KB Output is correct
23 Correct 2 ms 744 KB Output is correct
24 Correct 2 ms 744 KB Output is correct
25 Correct 2 ms 744 KB Output is correct
26 Correct 2 ms 744 KB Output is correct
27 Correct 2 ms 744 KB Output is correct
28 Correct 2 ms 744 KB Output is correct
29 Correct 2 ms 744 KB Output is correct
30 Correct 2 ms 744 KB Output is correct
31 Correct 2 ms 744 KB Output is correct
32 Correct 2 ms 744 KB Output is correct
33 Correct 2 ms 744 KB Output is correct
34 Correct 3 ms 744 KB Output is correct
35 Correct 2 ms 744 KB Output is correct
36 Correct 2 ms 744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 744 KB Output is correct
2 Correct 2 ms 744 KB Output is correct
3 Correct 2 ms 744 KB Output is correct
4 Correct 1 ms 744 KB Output is correct
5 Correct 2 ms 744 KB Output is correct
6 Correct 2 ms 744 KB Output is correct
7 Correct 2 ms 744 KB Output is correct
8 Correct 2 ms 744 KB Output is correct
9 Correct 2 ms 744 KB Output is correct
10 Correct 2 ms 744 KB Output is correct
11 Correct 2 ms 744 KB Output is correct
12 Correct 2 ms 744 KB Output is correct
13 Correct 2 ms 744 KB Output is correct
14 Correct 2 ms 744 KB Output is correct
15 Correct 2 ms 744 KB Output is correct
16 Correct 2 ms 744 KB Output is correct
17 Correct 2 ms 744 KB Output is correct
18 Correct 2 ms 744 KB Output is correct
19 Correct 2 ms 744 KB Output is correct
20 Correct 2 ms 744 KB Output is correct
21 Correct 2 ms 744 KB Output is correct
22 Correct 2 ms 744 KB Output is correct
23 Correct 2 ms 744 KB Output is correct
24 Correct 2 ms 744 KB Output is correct
25 Correct 2 ms 744 KB Output is correct
26 Correct 2 ms 744 KB Output is correct
27 Correct 2 ms 744 KB Output is correct
28 Correct 3 ms 744 KB Output is correct
29 Correct 3 ms 744 KB Output is correct
30 Correct 2 ms 744 KB Output is correct
31 Correct 2 ms 744 KB Output is correct
32 Correct 3 ms 744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 744 KB Output is correct
2 Correct 1 ms 744 KB Output is correct
3 Correct 2 ms 744 KB Output is correct
4 Correct 1 ms 744 KB Output is correct
5 Correct 2 ms 744 KB Output is correct
6 Correct 2 ms 744 KB Output is correct
7 Correct 2 ms 744 KB Output is correct
8 Correct 2 ms 744 KB Output is correct
9 Correct 2 ms 744 KB Output is correct
10 Correct 2 ms 744 KB Output is correct
11 Correct 2 ms 744 KB Output is correct
12 Correct 2 ms 744 KB Output is correct
13 Correct 2 ms 744 KB Output is correct
14 Correct 2 ms 744 KB Output is correct
15 Correct 2 ms 744 KB Output is correct
16 Correct 2 ms 744 KB Output is correct
17 Correct 2 ms 744 KB Output is correct
18 Correct 1 ms 744 KB Output is correct
19 Correct 1 ms 744 KB Output is correct
20 Correct 2 ms 744 KB Output is correct
21 Correct 2 ms 744 KB Output is correct
22 Correct 2 ms 744 KB Output is correct
23 Correct 2 ms 744 KB Output is correct
24 Correct 2 ms 744 KB Output is correct
25 Correct 2 ms 744 KB Output is correct
26 Correct 2 ms 744 KB Output is correct
27 Correct 2 ms 744 KB Output is correct
28 Correct 2 ms 744 KB Output is correct
29 Correct 2 ms 744 KB Output is correct
30 Correct 2 ms 744 KB Output is correct
31 Correct 1 ms 744 KB Output is correct
32 Correct 1 ms 744 KB Output is correct
33 Correct 1 ms 744 KB Output is correct
34 Correct 1 ms 744 KB Output is correct
35 Correct 2 ms 744 KB Output is correct
36 Correct 2 ms 744 KB Output is correct
37 Correct 2 ms 744 KB Output is correct
38 Correct 2 ms 744 KB Output is correct
39 Correct 2 ms 744 KB Output is correct
40 Correct 2 ms 744 KB Output is correct
41 Correct 2 ms 744 KB Output is correct
42 Correct 2 ms 744 KB Output is correct
43 Correct 2 ms 744 KB Output is correct
44 Correct 2 ms 744 KB Output is correct
45 Correct 2 ms 744 KB Output is correct
46 Correct 2 ms 744 KB Output is correct
47 Correct 2 ms 744 KB Output is correct
48 Correct 2 ms 744 KB Output is correct
49 Correct 2 ms 744 KB Output is correct
50 Correct 2 ms 744 KB Output is correct
51 Correct 2 ms 744 KB Output is correct
52 Correct 3 ms 744 KB Output is correct
53 Correct 3 ms 744 KB Output is correct
54 Correct 2 ms 744 KB Output is correct
55 Correct 3 ms 744 KB Output is correct
56 Correct 2 ms 744 KB Output is correct
57 Correct 2 ms 744 KB Output is correct
58 Correct 2 ms 744 KB Output is correct
59 Correct 2 ms 744 KB Output is correct
60 Correct 2 ms 744 KB Output is correct
61 Correct 2 ms 744 KB Output is correct
62 Correct 2 ms 744 KB Output is correct
63 Correct 2 ms 744 KB Output is correct
64 Execution timed out 1065 ms 832 KB Time limit exceeded
65 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 832 KB Output is correct
2 Correct 2 ms 832 KB Output is correct
3 Correct 1 ms 832 KB Output is correct
4 Correct 2 ms 832 KB Output is correct
5 Correct 1 ms 832 KB Output is correct
6 Correct 2 ms 832 KB Output is correct
7 Correct 2 ms 832 KB Output is correct
8 Correct 2 ms 832 KB Output is correct
9 Correct 2 ms 832 KB Output is correct
10 Correct 1 ms 832 KB Output is correct
11 Correct 2 ms 832 KB Output is correct
12 Correct 2 ms 832 KB Output is correct
13 Correct 2 ms 832 KB Output is correct
14 Correct 2 ms 832 KB Output is correct
15 Correct 2 ms 832 KB Output is correct
16 Correct 1 ms 832 KB Output is correct
17 Correct 1 ms 832 KB Output is correct
18 Correct 2 ms 832 KB Output is correct
19 Correct 2 ms 832 KB Output is correct
20 Correct 2 ms 832 KB Output is correct
21 Correct 2 ms 832 KB Output is correct
22 Correct 2 ms 832 KB Output is correct
23 Correct 2 ms 832 KB Output is correct
24 Correct 2 ms 832 KB Output is correct
25 Correct 2 ms 832 KB Output is correct
26 Correct 2 ms 832 KB Output is correct
27 Correct 2 ms 832 KB Output is correct
28 Correct 2 ms 832 KB Output is correct
29 Correct 2 ms 832 KB Output is correct
30 Correct 2 ms 832 KB Output is correct
31 Correct 2 ms 832 KB Output is correct
32 Correct 2 ms 832 KB Output is correct
33 Correct 2 ms 832 KB Output is correct
34 Correct 2 ms 832 KB Output is correct
35 Correct 2 ms 832 KB Output is correct
36 Correct 2 ms 832 KB Output is correct
37 Correct 2 ms 832 KB Output is correct
38 Correct 2 ms 832 KB Output is correct
39 Correct 2 ms 832 KB Output is correct
40 Correct 3 ms 832 KB Output is correct
41 Correct 2 ms 832 KB Output is correct
42 Correct 4 ms 832 KB Output is correct
43 Correct 2 ms 832 KB Output is correct
44 Correct 2 ms 832 KB Output is correct
45 Correct 2 ms 832 KB Output is correct
46 Correct 2 ms 832 KB Output is correct
47 Correct 2 ms 832 KB Output is correct
48 Correct 2 ms 832 KB Output is correct
49 Correct 2 ms 832 KB Output is correct
50 Correct 2 ms 832 KB Output is correct
51 Correct 2 ms 832 KB Output is correct
52 Correct 11 ms 832 KB Output is correct
53 Correct 12 ms 832 KB Output is correct
54 Correct 54 ms 832 KB Output is correct
55 Correct 26 ms 876 KB Output is correct
56 Correct 59 ms 876 KB Output is correct
57 Correct 57 ms 1004 KB Output is correct
58 Correct 65 ms 1004 KB Output is correct
59 Correct 95 ms 1004 KB Output is correct
60 Correct 82 ms 1004 KB Output is correct
61 Correct 2 ms 1004 KB Output is correct
62 Correct 13 ms 1004 KB Output is correct
63 Correct 38 ms 1004 KB Output is correct
64 Correct 17 ms 1004 KB Output is correct
65 Correct 29 ms 1004 KB Output is correct
66 Correct 43 ms 1004 KB Output is correct
67 Correct 56 ms 1004 KB Output is correct
68 Correct 127 ms 1004 KB Output is correct
69 Correct 54 ms 1004 KB Output is correct