Submission #45201

# Submission time Handle Problem Language Result Execution time Memory
45201 2018-04-11T19:41:35 Z ckodser Bali Sculptures (APIO15_sculpture) C++14
50 / 100
235 ms 1092 KB
#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll> 

using namespace :: std;

const ll maxn=2100;
const ll mod=1e9+7;
const ll inf=1e18+500;

ll a[maxn];
ll n,A,B;



ll dpa1[maxn];
bool shoda1(ll res){
	dpa1[0]=0;
	for(ll i=1;i<=n;i++){
		dpa1[i]=inf;
		ll sum=0;
		for(ll j=i;j>=1;j--){
			sum+=a[j];
			if((sum|res)==res){
				dpa1[i]=min(dpa1[i],dpa1[j-1]+1);
			}
		}
	}
	if(dpa1[n]<=B){
		return 1;
	}
	return 0;
}
bool dp[maxn][maxn];
bool shod(ll res){
	dp[0][0]=1;
	for(ll i=1;i<=n;i++){
		for(ll z=1;z<=n;z++){
			ll sum=0;
			for(ll j=i;j>=1;j--){
				sum+=a[j];
				if((sum|res)==res){
					dp[i][z]|=dp[j-1][z-1];
				}
			}
		}
	}
	for(ll i=A;i<=B;i++){
		if(dp[n][i]){
			return 1;
		}
	}
	return 0;
}
int main(){	
	cin>>n>>A>>B;

	for(ll i=1;i<=n;i++){
		cin>>a[i];
	}
	if(A==1){
		ll res=0;
		for(ll i=60;i>=0;i--){
			if(!shoda1(res+(1LL<<i)-1)){
				res+=(1LL<<i);	
			}	
		}
		cout<<res<<endl;
	}
	else{
		ll res=0;
		for(ll i=60;i>=0;i--){
			if(!shod(res+(1LL<<i)-1)){
				res+=(1LL<<i);	
			}	
		}
		cout<<res<<endl;
	}
}
/*    
	  .      _______    __    ___     ________      ________       _________     _________   ________
	  .     /       \  |  |  /  /    /        \    |        \     /         \   |        |  |   __   \
	  .    /   _____/  |  | /  /    /    ___   \   |   ___   \   |   _______/   |  ______|  |  |  \   \
	  .   /   /        |  |/  /    /    /   \   \  |  |   \   \  |  (______     |  |_____   |  |__/   /
	  .   |  |         |     /     |   /     \  |  |  |    |  |   \        \    |        |  |      __/
	  .   |  |         |     \     |   \     /  |  |  |    |  |    \______  \   |  ______|  |      \
	  .   \   \_____   |  |\  \    \    \___/   /  |  |___/   /    _______) |   |  |_____   |   |\  \
	  .    \        \  |  | \  \    \          /   |         /    /         /   |        |  |   | \  \
	  .     \_______/  |__|  \__\    \________/    |________/     \________/    |________|  |___|  \__\
 */
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 536 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Correct 2 ms 616 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Correct 2 ms 616 KB Output is correct
8 Correct 2 ms 616 KB Output is correct
9 Correct 2 ms 616 KB Output is correct
10 Correct 2 ms 616 KB Output is correct
11 Correct 2 ms 616 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Incorrect 2 ms 624 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 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 2 ms 636 KB Output is correct
4 Correct 2 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 2 ms 636 KB Output is correct
8 Correct 2 ms 636 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 2 ms 636 KB Output is correct
11 Correct 2 ms 636 KB Output is correct
12 Correct 2 ms 636 KB Output is correct
13 Correct 2 ms 636 KB Output is correct
14 Incorrect 2 ms 636 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 636 KB Output is correct
2 Correct 2 ms 636 KB Output is correct
3 Correct 2 ms 636 KB Output is correct
4 Correct 2 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 2 ms 636 KB Output is correct
8 Correct 2 ms 636 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 2 ms 636 KB Output is correct
11 Correct 2 ms 636 KB Output is correct
12 Correct 2 ms 636 KB Output is correct
13 Correct 2 ms 636 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 2 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 2 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 2 ms 636 KB Output is correct
22 Correct 2 ms 636 KB Output is correct
23 Correct 2 ms 636 KB Output is correct
24 Correct 2 ms 636 KB Output is correct
25 Correct 2 ms 636 KB Output is correct
26 Correct 2 ms 636 KB Output is correct
27 Correct 3 ms 636 KB Output is correct
28 Correct 3 ms 636 KB Output is correct
29 Correct 3 ms 636 KB Output is correct
30 Correct 3 ms 636 KB Output is correct
31 Correct 3 ms 636 KB Output is correct
32 Correct 3 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 636 KB Output is correct
2 Correct 2 ms 636 KB Output is correct
3 Correct 2 ms 636 KB Output is correct
4 Correct 2 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 2 ms 636 KB Output is correct
8 Correct 2 ms 636 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 2 ms 636 KB Output is correct
11 Correct 2 ms 636 KB Output is correct
12 Correct 2 ms 636 KB Output is correct
13 Correct 2 ms 636 KB Output is correct
14 Incorrect 2 ms 636 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 636 KB Output is correct
2 Correct 2 ms 636 KB Output is correct
3 Correct 2 ms 636 KB Output is correct
4 Correct 2 ms 752 KB Output is correct
5 Correct 2 ms 752 KB Output is correct
6 Correct 2 ms 752 KB Output is correct
7 Correct 2 ms 752 KB Output is correct
8 Correct 2 ms 752 KB Output is correct
9 Correct 2 ms 752 KB Output is correct
10 Correct 2 ms 760 KB Output is correct
11 Correct 2 ms 760 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
13 Correct 2 ms 760 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 2 ms 760 KB Output is correct
16 Correct 2 ms 760 KB Output is correct
17 Correct 2 ms 760 KB Output is correct
18 Correct 2 ms 760 KB Output is correct
19 Correct 2 ms 760 KB Output is correct
20 Correct 2 ms 760 KB Output is correct
21 Correct 2 ms 760 KB Output is correct
22 Correct 2 ms 760 KB Output is correct
23 Correct 2 ms 760 KB Output is correct
24 Correct 2 ms 760 KB Output is correct
25 Correct 2 ms 760 KB Output is correct
26 Correct 2 ms 760 KB Output is correct
27 Correct 2 ms 760 KB Output is correct
28 Correct 2 ms 760 KB Output is correct
29 Correct 2 ms 760 KB Output is correct
30 Correct 2 ms 760 KB Output is correct
31 Correct 2 ms 760 KB Output is correct
32 Correct 2 ms 760 KB Output is correct
33 Correct 2 ms 760 KB Output is correct
34 Correct 2 ms 760 KB Output is correct
35 Correct 2 ms 760 KB Output is correct
36 Correct 2 ms 760 KB Output is correct
37 Correct 3 ms 760 KB Output is correct
38 Correct 3 ms 760 KB Output is correct
39 Correct 3 ms 760 KB Output is correct
40 Correct 3 ms 760 KB Output is correct
41 Correct 3 ms 760 KB Output is correct
42 Correct 3 ms 760 KB Output is correct
43 Correct 2 ms 760 KB Output is correct
44 Correct 2 ms 760 KB Output is correct
45 Correct 1 ms 760 KB Output is correct
46 Correct 3 ms 760 KB Output is correct
47 Correct 2 ms 760 KB Output is correct
48 Correct 3 ms 760 KB Output is correct
49 Correct 2 ms 760 KB Output is correct
50 Correct 3 ms 760 KB Output is correct
51 Correct 2 ms 760 KB Output is correct
52 Correct 22 ms 760 KB Output is correct
53 Correct 34 ms 760 KB Output is correct
54 Correct 60 ms 760 KB Output is correct
55 Correct 59 ms 760 KB Output is correct
56 Correct 235 ms 760 KB Output is correct
57 Correct 223 ms 760 KB Output is correct
58 Correct 213 ms 816 KB Output is correct
59 Correct 213 ms 816 KB Output is correct
60 Correct 223 ms 816 KB Output is correct
61 Correct 3 ms 816 KB Output is correct
62 Correct 34 ms 816 KB Output is correct
63 Correct 61 ms 908 KB Output is correct
64 Correct 59 ms 908 KB Output is correct
65 Correct 110 ms 908 KB Output is correct
66 Correct 170 ms 1032 KB Output is correct
67 Correct 221 ms 1032 KB Output is correct
68 Correct 223 ms 1032 KB Output is correct
69 Correct 217 ms 1092 KB Output is correct