Submission #199403

# Submission time Handle Problem Language Result Execution time Memory
199403 2020-02-01T08:27:41 Z detaomega Bali Sculptures (APIO15_sculpture) C++14
0 / 100
6 ms 376 KB
//#include "cave.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define de(x,y) cout<<#x<<" :"<<x<<y;
#define int long long
typedef pair<int,int> pii;

const int maxn = 1e2+5;

int arr[2005], ans = 0, n, A, B;
int pre[2005];
int two[60];
void solve() {
	int dp[maxn][maxn];
	int digit = __lg(pre[n]);
	for(int x=digit; x>=0; x--) {
		memset(dp, 0, sizeof(dp));
		dp[0][0] = 1;
		for(int i=1; i<=n; i++) {
			for(int j=1; j<=i; j++) {
				for(int k=0; k<i; k++) {
					if(dp[k][j-1]) {
						int tmp = pre[i] - pre[k];
						if((tmp & (two[x])) == 0 &&((tmp>>(int)(x+1))|ans)==ans ) {
							dp[i][j] = 1;
						}
					}
				} 
			} 
		}	
		ans<<=1;
		ans++; 
		for(int i=A; i<=B; i++) {
			if(dp[n][i]) {
				ans--;
				break;
			}
		}
	}
}
void solve2() {
	int dp[2005];
	memset(dp, 0, sizeof(dp));
	for(int i=1; i<=n; i++) {
		dp[i] = 3005;
	}
	dp[0] = 1;
	int digit = __lg(pre[n]);
	for(int x=digit; x>=0; x--) {
		memset(dp, 0, sizeof(dp));
		for(int i=1; i<=n; i++) {
			dp[i] = 3005;
		}
		dp[0] = 1;
		for(int i=1; i<=n; i++) {
			for(int j=0; j<i; j++) {
				if(dp[j]) {
					int tmp = pre[i] - pre[j];
					if((tmp & (two[x])) == 0 &&((tmp>>(int)(x+1))|ans)==ans ) {
						dp[i] = min(dp[i], dp[j]+1);
					}
				}
			}
		}
		ans <<= 1;
		ans++;
		if(dp[n]>B)ans--;
	}
}
main() {IOS
//	int n, A, B;
	cin >> n >> A >> B;
	two[0] = 1;
	for(int i=1; i<=50; i++) {
		two[i] = two[i-1] * 2;
	}
	pre[0] = 0;
	for(int i=1; i<=n; i++) {
		cin >> arr[i];
		pre[i] = pre[i-1] + arr[i];
	}
	if(A==1)solve2();
	else
		solve();
	cout << ans << "\n"; 



}

Compilation message

sculpture.cpp:74:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {IOS
      ^
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -