Submission #659729

#TimeUsernameProblemLanguageResultExecution timeMemory
659729four_specksBali Sculptures (APIO15_sculpture)C++17
100 / 100
80 ms340 KiB
#include <bits/stdc++.h> using namespace std; inline namespace { } // namespace void solve() { int n, a, b; cin >> n >> a >> b; vector<long> y(n); for (long &u : y) cin >> u; vector<long> pref(n + 1); pref[0] = 0; for (int i = 0; i < n; i++) pref[i + 1] = pref[i] + y[i]; long res = 0; if (n <= 100) { for (int s = __lg(pref[n]); s >= 0; s--) { long comp = ~((1l << s) - 1); vector dp(n + 1, vector<bool>(b + 1, 0)); dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int k = 1; k <= b; k++) { for (int j = 0; j < i; j++) { if ((res | ((pref[i] - pref[j]) & comp)) == res) { if (dp[j][k - 1]) { dp[i][k] = 1; break; } } } } } bool ok = 0; for (int i = a; i <= b; i++) { if (dp[n][i]) { ok = 1; break; } } if (!ok) res |= 1l << s; } } else { for (int s = __lg(pref[n]); s >= 0; s--) { long comp = ~((1l << s) - 1); vector<int> dp(n + 1, n + 1); dp[0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < i; j++) { if ((res | ((pref[i] - pref[j]) & comp)) == res) dp[i] = min(dp[i], dp[j] + 1); } } if (dp[n] > b) res |= 1l << s; } } cout << res << '\n'; } int main() { ios_base::sync_with_stdio(false), cin.tie(NULL); solve(); 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...