Submission #151028

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