# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1128003 | VinhLuu | Bali Sculptures (APIO15_sculpture) | C++17 | 61 ms | 480 KiB |
#include <bits/stdc++.h>
#define ll long long
#define all(lpv) lpv.begin(), lpv.end()
#define pot(x, y) lower_bound(x.begin(), x.end(), y) - x.begin() + 1
using namespace std;
#define lpv
#ifndef lpv
#include "AC.h"
#endif // lpv
//#define int long long
const int N = 2e3 + 5;
int n, a[N], L, R;
ll s[N];
namespace sub4 {
bool f[N][N];
void solve() {
ll ret = 0, kq = 0;
for(int bit = 36; bit >= 0; bit --) {
for(int i = 0; i <= n; i ++) {
for(int j = 0; j <= i; j ++) f[i][j] = 0;
}
f[0][0] = 1;
for(int i = 1; i <= n; i ++) for(int j = 1; j <= i; j ++) {
for(int pos = i - 1; pos >= j - 1; pos --) {
if(!((s[i] - s[j]) & (ret + (1ll << bit))))
f[i][j] = max(f[i][j], f[pos][j - 1]);
}
}
bool ff = true;
for(int i = L; i <= R; i ++) if(f[n][i]) {
ff = false;
break;
}
if(!ff) ret += (1ll << bit);
else kq += (1ll << bit);
}
cout << kq;
}
}
namespace sub5 {
int f[N];
const int oo = 1e9;
void solve() {
ll ret = 0, kq = 0;
for(int bit = 40; bit >= 0; bit --) {
for(int i = 0; i <= n; i ++) f[i] = n + 1;
f[0] = 0;
for(int i = 1; i <= n; i ++) {
for(int j = i - 1; j >= 0; j --) {
if(!((s[i] - s[j]) & (ret + (1ll << bit))))
f[i] = min(f[i], f[j] + 1);
}
}
if(f[n] <= R) ret += (1ll << bit);
else kq += (1ll << bit);
}
cout << kq << "\n";
}
}
#ifdef lpv
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "v"
if(fopen(task ".inp","r")) {
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
cin >> n >> L >> R;
for(int i = 1; i <= n; i ++) {
cin >> a[i];
s[i] = s[i - 1] + a[i];
}
// if(n <= 100 && L > 1) sub4 :: solve();
// else
sub5 :: solve();
}
#endif // lpv
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... |