Submission #925491

#TimeUsernameProblemLanguageResultExecution timeMemory
925491VMaksimoski008Bali Sculptures (APIO15_sculpture)C++14
50 / 100
121 ms600 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int32_t main() { int n, a, b; cin >> n >> a >> b; vector<ll> pref(n+1); for(int i=1; i<=n; i++) cin >> pref[i], pref[i] += pref[i-1]; auto query = [&](int l, int r) { return pref[r] - pref[l-1]; }; if(a == 1) { ll mask = 0; for(int bit=51; bit>=0; bit--) { ll mask2 = mask | (1ll << bit); vector<int> dp(n+1, 1e9); dp[0] = 0; for(int i=1; i<=n; i++) { for(int j=i; j>=1; j--) { if(query(j, i) & mask2) continue; dp[i] = min(dp[i], dp[j-1] + 1); } } if(dp[n] <= b) mask |= (1ll << bit); } mask ^= ((1ll << 52) - 1); cout << mask << '\n'; return 0; } ll mask = 0, dp[n+1][n+1]; for(int bit=51; bit>=0; bit--) { ll mask2 = mask | (1ll << bit); for(int i=0; i<=n; i++) for(int j=0; j<=n; j++) dp[i][j] = 0; dp[0][0] = 1; for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { for(int k=1; k<=i; k++) { if(query(k, j) & mask2) continue; dp[i][j] |= dp[k-1][j-1]; } } } for(int j=a; j<=b; j++) { if(dp[n][j]) { mask |= (1ll << bit); break; } } } mask ^= ((1ll << 52) - 1); cout << mask << '\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...