Submission #45200

# Submission time Handle Problem Language Result Execution time Memory
45200 2018-04-11T19:38:11 Z ckodser Bali Sculptures (APIO15_sculpture) C++14
46 / 100
231 ms 1340 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=2000;
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;

	if(n<=20){
		for(ll i=0;i<n;i++){
			cin>>a[i];
		}
		ll ans=inf;
		for(ll i=0;i<(1LL<<(n-1));i++){
			ll yek=__builtin_popcount(i)+1;
			if(A<=yek && yek<=B){
				ll sum=0;
				ll orr=0;
				for(ll j=0;j<n;j++){
					sum+=a[j];
					if((i>>j)&1){
						orr|=sum;
						sum=0;
					}	
				}
				orr|=sum;
				ans=min(ans,orr);
			}
		}
		cout<<ans;
		return 0;
	}
	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 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 3 ms 536 KB Output is correct
7 Correct 13 ms 536 KB Output is correct
8 Correct 4 ms 544 KB Output is correct
9 Correct 4 ms 544 KB Output is correct
10 Correct 4 ms 552 KB Output is correct
11 Correct 4 ms 552 KB Output is correct
12 Correct 4 ms 556 KB Output is correct
13 Correct 45 ms 556 KB Output is correct
14 Correct 2 ms 556 KB Output is correct
15 Correct 2 ms 612 KB Output is correct
16 Correct 2 ms 616 KB Output is correct
17 Correct 2 ms 624 KB Output is correct
18 Correct 2 ms 656 KB Output is correct
19 Correct 2 ms 700 KB Output is correct
20 Correct 2 ms 720 KB Output is correct
21 Correct 8 ms 720 KB Output is correct
22 Correct 7 ms 720 KB Output is correct
23 Correct 7 ms 860 KB Output is correct
24 Correct 4 ms 860 KB Output is correct
25 Correct 7 ms 860 KB Output is correct
26 Correct 41 ms 860 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 3 ms 860 KB Output is correct
31 Correct 7 ms 860 KB Output is correct
32 Correct 4 ms 860 KB Output is correct
33 Correct 40 ms 932 KB Output is correct
34 Correct 44 ms 932 KB Output is correct
35 Correct 5 ms 932 KB Output is correct
36 Correct 45 ms 932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 932 KB Output is correct
2 Correct 2 ms 932 KB Output is correct
3 Correct 2 ms 932 KB Output is correct
4 Correct 2 ms 932 KB Output is correct
5 Correct 2 ms 932 KB Output is correct
6 Correct 8 ms 932 KB Output is correct
7 Correct 2 ms 932 KB Output is correct
8 Correct 4 ms 932 KB Output is correct
9 Correct 4 ms 932 KB Output is correct
10 Correct 4 ms 932 KB Output is correct
11 Correct 4 ms 932 KB Output is correct
12 Correct 4 ms 932 KB Output is correct
13 Correct 44 ms 932 KB Output is correct
14 Correct 2 ms 932 KB Output is correct
15 Correct 2 ms 932 KB Output is correct
16 Correct 2 ms 932 KB Output is correct
17 Correct 2 ms 932 KB Output is correct
18 Correct 2 ms 932 KB Output is correct
19 Correct 2 ms 956 KB Output is correct
20 Correct 2 ms 956 KB Output is correct
21 Correct 7 ms 956 KB Output is correct
22 Correct 7 ms 980 KB Output is correct
23 Correct 8 ms 980 KB Output is correct
24 Correct 4 ms 980 KB Output is correct
25 Correct 7 ms 980 KB Output is correct
26 Correct 40 ms 980 KB Output is correct
27 Correct 2 ms 980 KB Output is correct
28 Correct 2 ms 980 KB Output is correct
29 Correct 2 ms 980 KB Output is correct
30 Correct 2 ms 980 KB Output is correct
31 Correct 2 ms 980 KB Output is correct
32 Correct 2 ms 980 KB Output is correct
33 Correct 3 ms 980 KB Output is correct
34 Correct 2 ms 980 KB Output is correct
35 Correct 2 ms 980 KB Output is correct
36 Correct 2 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 980 KB Output is correct
2 Correct 2 ms 980 KB Output is correct
3 Correct 2 ms 980 KB Output is correct
4 Correct 2 ms 980 KB Output is correct
5 Correct 2 ms 980 KB Output is correct
6 Correct 3 ms 980 KB Output is correct
7 Correct 2 ms 980 KB Output is correct
8 Correct 4 ms 980 KB Output is correct
9 Correct 4 ms 980 KB Output is correct
10 Correct 4 ms 980 KB Output is correct
11 Correct 4 ms 980 KB Output is correct
12 Correct 23 ms 980 KB Output is correct
13 Correct 44 ms 980 KB Output is correct
14 Correct 2 ms 980 KB Output is correct
15 Correct 2 ms 980 KB Output is correct
16 Correct 2 ms 980 KB Output is correct
17 Correct 2 ms 980 KB Output is correct
18 Correct 2 ms 980 KB Output is correct
19 Correct 2 ms 980 KB Output is correct
20 Correct 2 ms 980 KB Output is correct
21 Correct 2 ms 980 KB Output is correct
22 Correct 2 ms 980 KB Output is correct
23 Correct 2 ms 980 KB Output is correct
24 Correct 2 ms 980 KB Output is correct
25 Correct 2 ms 980 KB Output is correct
26 Correct 2 ms 980 KB Output is correct
27 Correct 2 ms 980 KB Output is correct
28 Correct 3 ms 980 KB Output is correct
29 Correct 3 ms 980 KB Output is correct
30 Correct 3 ms 980 KB Output is correct
31 Correct 3 ms 980 KB Output is correct
32 Correct 3 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 980 KB Output is correct
2 Correct 2 ms 980 KB Output is correct
3 Correct 2 ms 980 KB Output is correct
4 Correct 2 ms 980 KB Output is correct
5 Correct 2 ms 980 KB Output is correct
6 Correct 3 ms 980 KB Output is correct
7 Correct 2 ms 980 KB Output is correct
8 Correct 4 ms 980 KB Output is correct
9 Correct 5 ms 980 KB Output is correct
10 Correct 4 ms 980 KB Output is correct
11 Correct 5 ms 980 KB Output is correct
12 Correct 4 ms 980 KB Output is correct
13 Correct 45 ms 980 KB Output is correct
14 Correct 2 ms 980 KB Output is correct
15 Correct 2 ms 980 KB Output is correct
16 Correct 2 ms 980 KB Output is correct
17 Correct 2 ms 980 KB Output is correct
18 Correct 2 ms 980 KB Output is correct
19 Correct 2 ms 980 KB Output is correct
20 Correct 2 ms 980 KB Output is correct
21 Correct 7 ms 980 KB Output is correct
22 Correct 7 ms 980 KB Output is correct
23 Correct 7 ms 980 KB Output is correct
24 Correct 4 ms 980 KB Output is correct
25 Correct 7 ms 980 KB Output is correct
26 Correct 40 ms 980 KB Output is correct
27 Correct 2 ms 980 KB Output is correct
28 Correct 2 ms 980 KB Output is correct
29 Correct 2 ms 980 KB Output is correct
30 Correct 3 ms 980 KB Output is correct
31 Correct 7 ms 980 KB Output is correct
32 Correct 6 ms 980 KB Output is correct
33 Correct 42 ms 988 KB Output is correct
34 Correct 44 ms 992 KB Output is correct
35 Correct 4 ms 992 KB Output is correct
36 Correct 44 ms 992 KB Output is correct
37 Correct 2 ms 1004 KB Output is correct
38 Correct 2 ms 1008 KB Output is correct
39 Correct 2 ms 1012 KB Output is correct
40 Correct 2 ms 1016 KB Output is correct
41 Correct 2 ms 1020 KB Output is correct
42 Correct 2 ms 1024 KB Output is correct
43 Correct 2 ms 1032 KB Output is correct
44 Correct 2 ms 1036 KB Output is correct
45 Correct 2 ms 1036 KB Output is correct
46 Correct 2 ms 1164 KB Output is correct
47 Correct 2 ms 1164 KB Output is correct
48 Correct 2 ms 1164 KB Output is correct
49 Correct 1 ms 1164 KB Output is correct
50 Correct 3 ms 1164 KB Output is correct
51 Correct 3 ms 1164 KB Output is correct
52 Correct 3 ms 1164 KB Output is correct
53 Correct 3 ms 1164 KB Output is correct
54 Correct 3 ms 1164 KB Output is correct
55 Correct 3 ms 1164 KB Output is correct
56 Correct 2 ms 1164 KB Output is correct
57 Correct 2 ms 1164 KB Output is correct
58 Correct 2 ms 1164 KB Output is correct
59 Correct 3 ms 1164 KB Output is correct
60 Correct 3 ms 1164 KB Output is correct
61 Correct 3 ms 1164 KB Output is correct
62 Correct 3 ms 1204 KB Output is correct
63 Correct 3 ms 1208 KB Output is correct
64 Incorrect 54 ms 1340 KB Output isn't correct
65 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1340 KB Output is correct
2 Correct 2 ms 1340 KB Output is correct
3 Correct 2 ms 1340 KB Output is correct
4 Correct 2 ms 1340 KB Output is correct
5 Correct 2 ms 1340 KB Output is correct
6 Correct 4 ms 1340 KB Output is correct
7 Correct 2 ms 1340 KB Output is correct
8 Correct 5 ms 1340 KB Output is correct
9 Correct 6 ms 1340 KB Output is correct
10 Correct 4 ms 1340 KB Output is correct
11 Correct 6 ms 1340 KB Output is correct
12 Correct 4 ms 1340 KB Output is correct
13 Correct 46 ms 1340 KB Output is correct
14 Correct 2 ms 1340 KB Output is correct
15 Correct 2 ms 1340 KB Output is correct
16 Correct 2 ms 1340 KB Output is correct
17 Correct 4 ms 1340 KB Output is correct
18 Correct 9 ms 1340 KB Output is correct
19 Correct 6 ms 1340 KB Output is correct
20 Correct 44 ms 1340 KB Output is correct
21 Correct 45 ms 1340 KB Output is correct
22 Correct 4 ms 1340 KB Output is correct
23 Correct 44 ms 1340 KB Output is correct
24 Correct 2 ms 1340 KB Output is correct
25 Correct 2 ms 1340 KB Output is correct
26 Correct 2 ms 1340 KB Output is correct
27 Correct 2 ms 1340 KB Output is correct
28 Correct 3 ms 1340 KB Output is correct
29 Correct 2 ms 1340 KB Output is correct
30 Correct 2 ms 1340 KB Output is correct
31 Correct 2 ms 1340 KB Output is correct
32 Correct 2 ms 1340 KB Output is correct
33 Correct 2 ms 1340 KB Output is correct
34 Correct 2 ms 1340 KB Output is correct
35 Correct 2 ms 1340 KB Output is correct
36 Correct 2 ms 1340 KB Output is correct
37 Correct 2 ms 1340 KB Output is correct
38 Correct 3 ms 1340 KB Output is correct
39 Correct 3 ms 1340 KB Output is correct
40 Correct 3 ms 1340 KB Output is correct
41 Correct 3 ms 1340 KB Output is correct
42 Correct 3 ms 1340 KB Output is correct
43 Correct 2 ms 1340 KB Output is correct
44 Correct 2 ms 1340 KB Output is correct
45 Correct 3 ms 1340 KB Output is correct
46 Correct 3 ms 1340 KB Output is correct
47 Correct 3 ms 1340 KB Output is correct
48 Correct 3 ms 1340 KB Output is correct
49 Correct 2 ms 1340 KB Output is correct
50 Correct 3 ms 1340 KB Output is correct
51 Correct 3 ms 1340 KB Output is correct
52 Correct 21 ms 1340 KB Output is correct
53 Correct 35 ms 1340 KB Output is correct
54 Correct 60 ms 1340 KB Output is correct
55 Correct 59 ms 1340 KB Output is correct
56 Incorrect 231 ms 1340 KB Output isn't correct
57 Halted 0 ms 0 KB -