Submission #414378

#TimeUsernameProblemLanguageResultExecution timeMemory
414378grtBali Sculptures (APIO15_sculpture)C++17
100 / 100
173 ms344 KiB
#include <bits/stdc++.h> #define ST first #define ND second #define PB push_back using namespace std; using ll = long long; using pi = pair<int,int>; using vi = vector<int>; const int nax = 2000 + 10, qax = 110, INF = 1e9 + 10; int n, a, b; int val[nax]; int dp[nax]; bool dp2[qax][qax]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> a >> b; for(int i = 1; i <= n; ++i) { cin >> val[i]; } if(a == 1) { ll num = (1LL << 45) - 1; for(int bit = 44; bit >= 0; --bit) { num ^= (1LL << bit); for(int i = 1; i <= n; ++i) { ll sum = 0; dp[i] = INF; for(int j = i; j >= 1; --j) { sum += val[j]; if((sum | num) == num) { dp[i] = min(dp[i], dp[j - 1] + 1); } } } if(dp[n] > b) { num ^= (1LL << bit); } } cout << num; } else { ll num = (1LL << 45) - 1; for(int bit = 44; bit >= 0; --bit) { num ^= (1LL << bit); dp2[0][0] = true; for(int i = 1; i <= n; ++i) { for(int used = 1; used <= b; ++used) { ll sum = 0; dp2[i][used] = false; for(int j = i; j >= 1; --j) { sum += val[j]; if((sum | num) == num) { dp2[i][used] |= dp2[j - 1][used - 1]; } } } } bool any = false; for(int i = a; i <= b; ++i) any |= dp2[n][i]; if(!any) num ^= (1LL << bit); } cout << num; } }
#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...