Submission #205332

# Submission time Handle Problem Language Result Execution time Memory
205332 2020-02-28T15:08:36 Z kshitij_sodani Bali Sculptures (APIO15_sculpture) C++17
100 / 100
118 ms 504 KB
#include <iostream>
#include <bits/stdc++.h>
 
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl "\n"
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	llo n,a,b;
	cin>>n>>a>>b;
	llo it[n];
	for(llo i=0;i<n;i++){
		cin>>it[i];
	}
	if(n<=100){
		llo dp[n][n];
		llo ans=0;

		memset(dp,0,sizeof(dp));
		llo pre[n];
		pre[0]=it[0];

		for(llo i=1;i<n;i++){
			pre[i]=pre[i-1]+it[i];
		}
		
		for(llo i=38;i>=0;i--){
			memset(dp,0,sizeof(dp));
			//cout<<ans<<endl;
			ans=ans+(((llo)1<<(i))-(llo)1);
		//	cout<<i<<endl;
			//cout<<ans<<endl;
			for(llo j=0;j<n;j++){
				for(llo k=0;k<min(j+1,b);k++){

					if(k==0){
						llo no=pre[j];
						no|=ans;
						if(no==ans){
							dp[j][k]=1;
						}
						continue;

					}
					
					for(llo l=0;l<j;l++){

						llo no=(pre[j]-pre[l]);
						no|=ans;

						if(dp[l][k-1]==1 and (no==ans)){
							dp[j][k]=1;
						}
					}
				}
			}
			ans-=(llo)(((llo)1<<(i))-(llo)1);
			//cout<<ans<<endl<<endl;
			llo st=1;
			for(llo j=a-1;j<b;j++){
				if(dp[n-1][j]==1){
					st=0;
					break;
				}
			}
			//cout<<i<<" "<<st<<endl;
			if(st){
				ans|=((llo)1<<i);
			}
		}
		
		cout<<ans<<endl;
	}
	else{
		llo dp[n];
		llo ans=0;

		memset(dp,0,sizeof(dp));
		llo pre[n];
		pre[0]=it[0];

		for(llo i=1;i<n;i++){
			pre[i]=pre[i-1]+it[i];
		}
		
		for(llo i=42;i>=0;i--){
			memset(dp,0,sizeof(dp));
			//cout<<ans<<endl;
			ans=ans+(((llo)1<<(i))-(llo)1);
		//	cout<<i<<endl;
			//cout<<ans<<endl;
			for(llo j=0;j<n;j++){

					llo no=pre[j];
					no|=ans;
					if(no==ans){
						dp[j]=1;
					}				
					for(llo l=0;l<j;l++){

						llo no=(pre[j]-pre[l]);
						no|=ans;
						if(dp[l]>0 and (no==ans)){
							if(dp[j]==0){
								dp[j]=dp[l]+1;
							}
							dp[j]=min(dp[j],dp[l]+1);
						}
					}
				
			}
			ans-=(llo)(((llo)1<<(i))-(llo)1);
			//cout<<ans<<endl<<endl;
			llo st=1;
			for(llo j=n-1;j<n;j++){
				if(dp[j]>0 and dp[j]<b+1){
					st=0;
					break;
				}
			}
			if(st){
				ans|=((llo)1<<i);
			}
		}
		
		cout<<ans<<endl;
	}
	/*llo nno=8|3;
	//cout<<nno<<endl;
 
 
 */
 
 
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 248 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 4 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 380 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 4 ms 376 KB Output is correct
16 Correct 5 ms 380 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 380 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 6 ms 376 KB Output is correct
31 Correct 6 ms 376 KB Output is correct
32 Correct 7 ms 376 KB Output is correct
33 Correct 6 ms 376 KB Output is correct
34 Correct 6 ms 376 KB Output is correct
35 Correct 7 ms 376 KB Output is correct
36 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 408 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 6 ms 380 KB Output is correct
18 Correct 7 ms 376 KB Output is correct
19 Correct 6 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 6 ms 376 KB Output is correct
22 Correct 6 ms 376 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 6 ms 376 KB Output is correct
25 Correct 6 ms 376 KB Output is correct
26 Correct 9 ms 376 KB Output is correct
27 Correct 17 ms 376 KB Output is correct
28 Correct 23 ms 380 KB Output is correct
29 Correct 23 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 19 ms 376 KB Output is correct
32 Correct 24 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 256 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 5 ms 376 KB Output is correct
37 Correct 5 ms 376 KB Output is correct
38 Correct 5 ms 376 KB Output is correct
39 Correct 5 ms 376 KB Output is correct
40 Correct 6 ms 376 KB Output is correct
41 Correct 6 ms 376 KB Output is correct
42 Correct 6 ms 376 KB Output is correct
43 Correct 5 ms 376 KB Output is correct
44 Correct 6 ms 376 KB Output is correct
45 Correct 6 ms 376 KB Output is correct
46 Correct 6 ms 376 KB Output is correct
47 Correct 6 ms 376 KB Output is correct
48 Correct 6 ms 376 KB Output is correct
49 Correct 9 ms 376 KB Output is correct
50 Correct 16 ms 376 KB Output is correct
51 Correct 24 ms 376 KB Output is correct
52 Correct 24 ms 380 KB Output is correct
53 Correct 5 ms 376 KB Output is correct
54 Correct 17 ms 376 KB Output is correct
55 Correct 23 ms 484 KB Output is correct
56 Correct 6 ms 376 KB Output is correct
57 Correct 8 ms 380 KB Output is correct
58 Correct 16 ms 376 KB Output is correct
59 Correct 18 ms 376 KB Output is correct
60 Correct 17 ms 376 KB Output is correct
61 Correct 5 ms 376 KB Output is correct
62 Correct 19 ms 376 KB Output is correct
63 Correct 20 ms 376 KB Output is correct
64 Correct 19 ms 376 KB Output is correct
65 Correct 6 ms 376 KB Output is correct
66 Correct 6 ms 376 KB Output is correct
67 Correct 8 ms 376 KB Output is correct
68 Correct 13 ms 380 KB Output is correct
69 Correct 18 ms 376 KB Output is correct
70 Correct 17 ms 376 KB Output is correct
71 Correct 5 ms 376 KB Output is correct
72 Correct 19 ms 376 KB Output is correct
73 Correct 18 ms 376 KB Output is correct
74 Correct 18 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 6 ms 376 KB Output is correct
29 Correct 6 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 6 ms 376 KB Output is correct
32 Correct 7 ms 376 KB Output is correct
33 Correct 6 ms 376 KB Output is correct
34 Correct 6 ms 376 KB Output is correct
35 Correct 6 ms 376 KB Output is correct
36 Correct 9 ms 376 KB Output is correct
37 Correct 16 ms 376 KB Output is correct
38 Correct 24 ms 376 KB Output is correct
39 Correct 23 ms 376 KB Output is correct
40 Correct 5 ms 376 KB Output is correct
41 Correct 17 ms 376 KB Output is correct
42 Correct 21 ms 376 KB Output is correct
43 Correct 6 ms 376 KB Output is correct
44 Correct 8 ms 376 KB Output is correct
45 Correct 13 ms 376 KB Output is correct
46 Correct 17 ms 376 KB Output is correct
47 Correct 17 ms 376 KB Output is correct
48 Correct 5 ms 376 KB Output is correct
49 Correct 19 ms 380 KB Output is correct
50 Correct 18 ms 376 KB Output is correct
51 Correct 5 ms 376 KB Output is correct
52 Correct 15 ms 376 KB Output is correct
53 Correct 23 ms 504 KB Output is correct
54 Correct 36 ms 376 KB Output is correct
55 Correct 33 ms 376 KB Output is correct
56 Correct 111 ms 376 KB Output is correct
57 Correct 118 ms 376 KB Output is correct
58 Correct 103 ms 444 KB Output is correct
59 Correct 101 ms 376 KB Output is correct
60 Correct 116 ms 448 KB Output is correct
61 Correct 6 ms 504 KB Output is correct
62 Correct 21 ms 376 KB Output is correct
63 Correct 35 ms 376 KB Output is correct
64 Correct 32 ms 504 KB Output is correct
65 Correct 56 ms 376 KB Output is correct
66 Correct 86 ms 376 KB Output is correct
67 Correct 113 ms 376 KB Output is correct
68 Correct 107 ms 380 KB Output is correct
69 Correct 108 ms 376 KB Output is correct