Submission #106843

#TimeUsernameProblemLanguageResultExecution timeMemory
106843DiuvenBali Sculptures (APIO15_sculpture)C++14
37 / 100
4 ms384 KiB
#include <bits/stdc++.h> using namespace std; typedef long long lint; typedef pair<int, int> pii; const int INF = 2e9; int _min(int x, int y){ return x<y ? x : y; } int n, l, r; lint A[2010], S[2010]; lint solve1(){ int D[2010]; lint obj = (1LL<<42LL)-1; for(int b=41; b>=0; b--){ D[0] = 0; obj ^= (1LL<<lint(b)); for(int i=1; i<=n; i++){ D[i] = INF; for(int k=0; k<i; k++){ if(((S[i]-S[k])|obj) != obj) continue; D[i] = _min(D[i], D[k] + 1); } } if(D[n]>r) obj |= (1<<b); } return obj; } lint solve2(){ bool D[101][101]; lint obj = (1LL<<42LL)-1; for(int b=41; b>=0; b--){ obj ^= (1LL<<lint(b)); for(int i=1; i<=n; i++) D[0][i] = false; for(int j=1; j<=n; j++) D[j][0] = false; D[0][0] = true; for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ D[i][j] = false; for(int k=0; k<i; k++){ D[i][j] |= D[k][j-1] && (((S[i]-S[k])|obj)==obj); } } } bool yay = false; for(int i=l; i<=r; i++) yay |= D[n][i]; if(!yay) obj |= (1LL<<lint(b)); } return obj; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>n>>l>>r; for(int i=1; i<=n; i++) cin>>A[i], S[i] = S[i-1] + A[i]; cout<<(l==1 ? solve1() : solve2())<<'\n'; return 0; }
#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...