Submission #552601

#TimeUsernameProblemLanguageResultExecution timeMemory
552601QwertyPiBali Sculptures (APIO15_sculpture)C++14
37 / 100
80 ms95008 KiB
#include <bits/stdc++.h>
#define int long long
#define INF (1LL << 60)
using namespace std;
const int N = 2001;
int dp[N][N], dp2[N];
int s[N], A[N];
vector<int> vals[N][N];
typedef uint32_t uint;
bool valid[N][N];
int n, a, b;
bool check(int mask){
	for(int i = 0; i < n; i++){
		for(int j = i; j < n; j++){
			int v = s[j + 1] - s[i];
			valid[i][j] = (v | mask) == mask;
		}
	}
	if(n < -100){
		fill(dp2 + 1, dp2 + n + 1, INF);
		for(int i = 0; i < n; i++){
			for(int j = 0; j <= i; j++){
				dp2[i + 1] = min(dp2[i + 1], dp2[j] + valid[j][i]);
			}
		}
		return dp2[n] <= b;
	}else{
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				dp[i][j] = false;
			}
		}
		dp[0][0] = true;
		for(int tr = 0; tr < n; tr++){
			for(int i = 0; i < n; i++){
				for(int j = i; j < n; j++){
					dp[tr + 1][j + 1] |= dp[tr][i] & valid[i][j];
				}
			}
		}
		bool ans = false;
		for(int i = a; i <= b; i++){
			ans |= dp[i][n];
		}
		return ans;
	}
}

int32_t main(){
	cin >> n >> a >> b;
	vals[0][0].push_back(0);
	for(int i = 1; i <= n; i++) cin >> A[i], s[i] = s[i - 1] + A[i];
	uint mask = 0;
	for(int j = 60; j >= 0; j--){
		if(!check(mask + (1LL << j) - 1)){
			mask += 1LL << j;
		}
	}
	cout << mask << endl;
}

Compilation message (stderr)

sculpture.cpp: In function 'bool check(long long int)':
sculpture.cpp:26:15: warning: array subscript -101 is below array bounds of 'long long int [2001]' [-Warray-bounds]
   26 |   return dp2[n] <= b;
      |          ~~~~~^
sculpture.cpp:6:15: note: while referencing 'dp2'
    6 | int dp[N][N], dp2[N];
      |               ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...