# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
708054 | DennisTran | Bali Sculptures (APIO15_sculpture) | C++17 | 570 ms | 262144 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.
#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FOD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int l, int r) { return l + rnd() % (r - l + 1); }
const int MAXN = 2005;
int N, L, R, a[MAXN];
long long sum[MAXN];
struct SUB1{
long long ans = 1e18;
vector <int> lim;
void check(int sz) {
sz--;
if (sz < L || sz > R) return;
sz++;
long long tmp = 0;
for (int i = 1; i < sz; i++) {
tmp |= (sum[lim[i]] - sum[lim[i - 1]]);
}
ans = min(ans, tmp);
}
void Try(int id) {
if (id == N + 1) {
if (lim.back() != N) return;
return void(check(lim.size()));
}
Try(id + 1);
lim.emplace_back(id);
Try(id + 1);
lim.pop_back();
}
void solve(void) {
lim.emplace_back(0);
Try(1);
cout << ans; exit(0);
}
} sub1;
struct SUB2{
unordered_set <long long> dp[MAXN][MAXN];
void solve(void) {
dp[0][0].insert(0);
REP(i, N) {
REP(j, min(i + 1, R)) {
for (long long x : dp[i][j]) {
FOR(nxt, i + 1, N)
dp[nxt][j + 1].insert(x | sum[nxt] - sum[i]);
}
}
}
long long ans = 1e18;
FOR(i, L, R)
for (long long x : dp[N][i]) ans = min(ans, x);
cout << ans;
}
} sub2;
signed main(void) {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
file("TASK");
cin >> N >> L >> R;
FOR(i, 1, N) {
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
}
if (N <= 20) sub1.solve();
sub2.solve();
cerr << "Time elapsed: " << TIME << " s.\n";
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... |