Submission #943330

#TimeUsernameProblemLanguageResultExecution timeMemory
943330HiepVu217Bali Sculptures (APIO15_sculpture)C++17
50 / 100
91 ms600 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 17, M = 1e2 + 17; int f[N], a[N], n, u, v; bool fz[M][M]; long long ans, s[N]; bool check (long long a, long long b, long long c) { return (a | b) < (b | c); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> u >> v; for (int i = 1; i <= n; ++i) { cin >> a[i]; s[i] = s[i - 1] + a[i]; } if (u == 1) { for (int i = 40; i >= 0; --i) { long long x = 1LL << i; for (int j = 1; j <= n; ++j) { f[j] = n + 1; for (int k = 0; k < j; ++k) { if (check (s[j] - s[k], ans, x)) { f[j] = min (f[j], f[k] + 1); } } } if (f[n] > v) { ans += x; } } } else { for (int i = 40; i >= 0; --i) { long long x = 1LL << i; for (int j = 1; j <= n; ++j) { fz[j][0] = 1; for (int k = 1; k <= n; ++k) { fz[j][k] = 0; } } fz[0][0] = 1; for (int j = 1; j <= n; ++j) { for (int k = 0; k < j; ++k) { if (check (s[j] - s[k], ans, x)) { for (int t = 1; t <= j + 1; ++t) { fz[j][t] = fz[k][t - 1]; } } } } bool z = 0; for (int j = u; j <= v; ++j) { if (fz[n][j]) { z = 1; } } if (!z) { ans += x; } } } cout << ans; }
#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...