# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
392611 | giorgikob | Bali Sculptures (APIO15_sculpture) | C++14 | 142 ms | 452 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
const int N = 2e5+5, mod = 1e9+7, sq = 500;
int n,a,b;
ll A[N];
ll answer = 0;
ll dp[N];
inline void test_case(){
cin >> n >> a >> b;
for(int i = 1; i <= n; i++){
cin >> A[i];
}
if(a == 1){
answer = (1LL<<61) - 1;
for(int bit = 60; bit >= 0; bit--){
answer ^= (1LL<<bit);
//cout << x << endl;
for(int i = 0; i <= n; i++) dp[i] = 1e9;
dp[0] = 0;
for(int i = 0; i <= n; i++){
//cout << dp[i] << " ";
if(dp[i] == 1e9) continue;
ll sum = 0;
for(int j = i+1; j <= n; j++){
sum += A[j];
if((sum | answer) == answer){
dp[j] = min(dp[j],dp[i]+1);
}
}
}
//cout << endl;
if(dp[n] > b){
answer |= (1LL<<bit);
}
}
} else {
bool dp[n+5][n+5];
answer = (1LL<<61) - 1;
for(int bit = 60; bit >= 0; bit--){
answer ^= (1LL<<bit);
for(int i = 0; i <= n; i++)
for(int j = 0; j <= n+1; j++)
dp[i][j] = 0;
dp[0][0] = 1;
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++){
if(dp[i][j] == 0) continue;
ll sum = 0;
for(int t = i+1; t <= n; t++){
sum += A[t];
if((sum | answer) == answer){
dp[t][j+1] |= 1;
}
}
}
}
bool ok = false;
for(int i = a; i <= b; i++){
ok |= dp[n][i];
}
if(!ok){
answer |= (1LL<<bit);
}
}
}
cout << answer << endl;
}
main(){
ios::sync_with_stdio(0);
int T = 1;
//cin >> T;
while(T--){
test_case();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |