# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1057150 | vjudge1 | Bali Sculptures (APIO15_sculpture) | C++17 | 162 ms | 35576 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 oo64 = LLONG_MAX;
const int MAXN = 2050;
int N, L, R;
int a[MAXN];
i64 ans = oo64;
namespace subtask1 {
bool is_subtask() {
return N <= 20;
}
void solution() {
if(is_subtask() == false) return;
for(int mask = 0; mask < (1 << N); mask++) {
vector<i64> b;
b.emplace_back(0);
int cb = (mask >> 0 & 1);
for(int i = 0; i < N; i++) {
if((mask >> i & 1) == cb)
b.back() += a[i + 1];
else {
b.emplace_back(a[i + 1]);
cb ^= 1;
}
}
i64 res = 0;
for(i64 x : b) res |= x;
if(L <= b.size() and b.size() <= R)
ans = min(ans, res);
}
cout << ans;
exit(0);
}
}
namespace subtask23 {
int dpL[MAXN][MAXN];
int dpR[MAXN][MAXN];
bool is_subtask() {
for(int i = 1; i <= N; i++) {
if(a[i] > 20) return false;
}
return N <= 100;
}
void solution() {
if(is_subtask() == false) return;
memset(dpL, 0x3f, sizeof dpL);
memset(dpR, -0x3f, sizeof dpR);
dpL[0][0] = dpR[0][0] = 0;
for(int i = 1; i <= N; i++) {
int cur = 0;
for(int j = i; j >= 1; j--) {
cur += a[j];
for(int mask = 0; mask < (1 << 11); mask++) {
dpL[i][mask | cur] = min(dpL[i][mask | cur], dpL[j - 1][mask] + 1);
dpR[i][mask | cur] = max(dpR[i][mask | cur], dpR[j - 1][mask] + 1);
}
}
}
for(int mask = 0; mask < (1 << 11); mask++) {
if(dpL[N][mask] > dpR[N][mask]) continue;
if((L <= dpL[N][mask] and dpR[N][mask] <= R) or
(L <= dpL[N][mask] and dpL[N][mask] <= R) or
(L <= dpR[N][mask] and dpR[N][mask] <= R))
cout << mask, exit(0);
}
cout << "-1";
exit(0);
}
}
namespace subtask4 {
bool is_subtask() {
return N <= 100;
}
bool dp[MAXN][MAXN];
bool check(i64 mask) {
memset(dp, false, sizeof dp);
dp[0][0] = true;
for(int i = 1; i <= N; i++) {
for(int z = 1; z <= i; z++) {
i64 cur = 0;
for(int j = i; j >= 1; j--) {
cur += a[j];
if((mask | cur) == mask)
dp[i][z] |= dp[j - 1][z - 1];
}
}
}
for(int i = L; i <= R; i++) {
if(dp[N][i]) return true;
}
return false;
}
void solution() {
if(is_subtask() == false) return;
const int B = 50;
i64 ans = (1LL << B) - 1;
for(int i = B - 1; i >= 0; i--) {
if(check(ans - (1LL << i)))
ans = ans - (1LL << i);
}
cout << ans;
exit(0);
}
}
namespace subtask5 {
int dp[MAXN];
bool is_subtask() {
return L == 1;
}
bool check(i64 mask) {
memset(dp, 0x3f, sizeof dp);
dp[0] = 0;
for(int i = 1; i <= N; i++) {
i64 cur = 0;
for(int j = i; j >= 1; j--) {
cur += a[j];
if((cur | mask) == mask)
dp[i] = min(dp[i], dp[j - 1] + 1);
}
}
return dp[N] <= R;
}
void solution() {
if(is_subtask() == false) return;
const int B = 50;
i64 ans = (1LL << B) - 1;
for(int i = B - 1; i >= 0; i--) {
if(check(ans - (1LL << i)))
ans = ans - (1LL << i);
}
cout << ans;
exit(0);
}
}
signed main() {
#define TASK "code"
if (fopen(TASK ".inp", "r")) {
freopen(TASK ".inp", "r", stdin);
freopen(TASK ".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> L >> R;
for(int i = 1; i <= N; i++) cin >> a[i];
subtask1::solution();
subtask23::solution();
subtask4::solution();
subtask5::solution();
return (0 ^ 0);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |