Submission #954286

#TimeUsernameProblemLanguageResultExecution timeMemory
954286tnknguyen_Bali Sculptures (APIO15_sculpture)C++14
100 / 100
73 ms604 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' #define pii pair<int, int> #define MASK(k) (1LL << (k)) const int MX = 2005; const int LG = 45; int a[MX]; int n, A, B; pii check(int mask){ vector<int> mi(n + 5, 1e18); vector<int> ma(n + 5, -1e18); mi[0] = ma[0] = 0; for(int i=1; i<=n; ++i){ int sum = 0; for(int j=i; j>=1; --j){ sum += a[j]; if((sum | mask) == mask){ mi[i] = min(mi[i], mi[j-1] + 1); ma[i] = max(ma[i], ma[j-1] + 1); } } } return {mi[n], ma[n]}; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("main.inp","r",stdin); //freopen("main.out","w",stdout); cin>>n>>A>>B; for(int i=1; i<=n; ++i){ cin>>a[i]; } int ans = MASK(LG) - 1; for(int i=LG-1; i>=0; --i){ int t = ans ^ MASK(i); pii p = check(t); if(p.second >= A && p.first <= B){ ans ^= MASK(i); } } cout<<ans; 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...