Submission #167480

#TimeUsernameProblemLanguageResultExecution timeMemory
167480WLZBali Sculptures (APIO15_sculpture)C++14
100 / 100
168 ms508 KiB
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, a, b; cin >> n >> a >> b; vector<long long> y(n + 1); for (int i = 1; i <= n; i++) { cin >> y[i]; } if (a == 1) { long long mask = 0; for (int k = 41; k >= 0; k--) { vector<int> dp(n + 1, INF); dp[0] = 0; for (int i = 1; i <= n; i++) { long long sum = y[i]; for (int j = i - 1; j >= 0; j--) { long long tmp = (sum >> k) << k; if ((tmp & mask) == tmp) { dp[i] = min(dp[i], dp[j] + 1); } sum += y[j]; } } if (dp[n] > b) { mask |= (1ll << k); } } cout << mask << '\n'; } else { long long mask = 0; for (int k = 41; k >= 0; k--) { vector< vector<int> > dp(n + 1, vector<int>(n + 1, 0)); dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int t = 1; t <= n; t++) { long long sum = y[i]; for (int j = i - 1; j >= 0; j--) { long long tmp = (sum >> k) << k; if ((tmp & mask) == tmp) { dp[i][t] |= dp[j][t - 1]; } sum += y[j]; } } } int pos = 0; for (int t = a; t <= b; t++) { if (dp[n][t]) { pos = 1; break; } } if (!pos) { mask |= (1ll << k); } } 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...