Submission #151048

#TimeUsernameProblemLanguageResultExecution timeMemory
151048AlexPop28Bali Sculptures (APIO15_sculpture)C++11
100 / 100
94 ms504 KiB
#include <bits/stdc++.h> using namespace std; const long long INF_LL = (1LL << 41) - 1; bool Solve(int n, int a, int b, long long mask, const vector<int> &v) { vector<vector<int>> dp(n + 1, vector<int>(b + 1)); dp[0][0] = 1; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= b; ++j) { long long sum = 0LL; for (int k = i; k >= 1; --k) { sum += v[k]; dp[i][j] |= dp[k - 1][j - 1] & ((sum | mask) == mask); } } } return *max_element(dp[n].begin() + a, dp[n].begin() + b + 1); } bool SolveA1(int n, int b, long long mask, const vector<int> &v) { vector<int> dp(n + 1, n + 1); dp[0] = 0; for (int i = 1; i <= n; ++i) { long long sum = 0LL; for (int j = i; j >= 1; --j) { sum += v[j]; if ((sum | mask) == mask) dp[i] = min(dp[i], dp[j - 1] + 1); } } return dp[n] <= b; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, a, b; cin >> n >> a >> b; vector<int> v(n + 1); for (int i = 1; i <= n; ++i) cin >> v[i]; auto Check = [&](long long mask) { return a == 1 ? SolveA1(n, b, mask, v) : Solve(n, a, b, mask, v); }; long long ans = INF_LL; for (int bit = 40; bit >= 0; --bit) { if (Check(ans ^ (1LL << bit))) ans ^= 1LL << bit; } cout << ans << endl; }
#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...