Submission #490759

#TimeUsernameProblemLanguageResultExecution timeMemory
490759hollwo_pelwBali Sculptures (APIO15_sculpture)C++17
71 / 100
13 ms4352 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2005, M = 105; int n, a, b; int64_t pre[N]; bool check1(int64_t cur, int bt) { vector<bool> ok(n + 1, 0); ok[0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j < i; j++) if (ok[j]) { int64_t f = (pre[i] - pre[j]) >> bt, s = cur >> bt; if ((f | s) == s) ok[i] = 1; } } return ok[n]; } bool dp[N][N]; bool check(int64_t cur, int bt) { if (n > 100) return check1(cur, bt); memset(dp, 0, sizeof dp); dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j < i; j++) { int64_t f = (pre[i] - pre[j]) >> bt, s = cur >> bt; if ((f | s) == s) { for (int k = 1; k <= j + 1; k++) dp[i][k] |= dp[j][k - 1]; } } } for (int i = a; i <= b; i++) if (dp[n][i]) return 1; return 0; } signed main() { cin.tie(0), cout.tie(0) -> sync_with_stdio(0); cin >> n >> a >> b; for (int i = 1, x; i <= n; i++) cin >> x, pre[i] = pre[i - 1] + x; int64_t res = 0; for (int i = 40; ~i; i--) { if (!check(res, i)) res |= 1ll << i; } cout << res; }
#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...