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;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int(1e9+7)
#define ln '\n'
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define in(v,x) (v.find(x) != v.end())
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 1e18+1;
#define int long long
const int MAXN = 1e2+1, LOG = 41;
int n,A,B;
int a[MAXN], p[MAXN], res[LOG];
bool dp[MAXN][MAXN], valid[MAXN][MAXN];
vector<int> v[MAXN][MAXN];
int dp1[MAXN];
void lolwhat() {
dp[0][0] = 1;
FOR(i,0,n) FOR(j,i,n) valid[i][j] = 1;
FORR(k,LOG-1,-1) {
FOR(i,0,n+1) {
FOR(j,1,n+1) dp[i][j] = 0;
}
FOR(j,0,n) {
FOR(i,0,n+1) {
FOR(l,i+1,n+1) {
dp[l][j+1] = dp[l][j+1] || (dp[i][j] && valid[i][l-1] && !v[i][l-1][k]);
}
}
}
res[k] = 1;
FOR(x,A,B+1) {
if (dp[n][x]) res[k] = 0;
}
FOR(i,0,n) {
FOR(j,i,n) {
if (v[i][j][k] && !res[k]) valid[i][j] = 0;
}
}
}
int ans = 0, cur = 1;
FOR(k,0,LOG+1) {
ans += cur*res[k];
cur *= 2;
}
cout << ans;
}
void lolbruh() {
dp1[0] = 0;
FOR(i,0,n) FOR(j,i,n) valid[i][j] = 1;
FORR(k,LOG-1,-1) {
FOR(i,1,n+1) dp1[i] = LLINF;
FOR(i,0,n+1) {
FOR(l,i+1,n+1) {
if (valid[i][l-1] && !v[i][l-1][k]) {
dp1[l] = min(dp1[l], dp1[i]+1);
}
}
}
res[k] = dp1[n] <= B ? 0 : 1;
FOR(i,0,n) {
FOR(j,i,n) {
if (v[i][j][k] && !res[k]) valid[i][j] = 0;
}
}
}
int ans = 0, cur = 1;
FOR(k,0,LOG+1) {
ans += cur*res[k];
cur *= 2;
}
cout << ans;
}
signed main() {
OPTM;
cin >> n >> A >> B;
FOR(i,0,n) cin >> a[i];
FOR(i,1,n+1) p[i] = p[i-1]+a[i-1];
FOR(i,0,n) {
FOR(j,i,n) {
int x = p[j+1]-p[i];
while (x > 0) {
v[i][j].PB(x%2);
x /= 2;
}
int vn = v[i][j].size();
FOR(k,0,LOG-vn) v[i][j].PB(0);
}
}
if (A == 1) lolbruh();
else lolwhat();
}
Compilation message (stderr)
sculpture.cpp: In function 'void lolwhat()':
sculpture.cpp:59:25: warning: iteration 41 invokes undefined behavior [-Waggressive-loop-optimizations]
59 | ans += cur*res[k];
| ~~~~~^
sculpture.cpp:10:38: note: within this loop
10 | #define FOR(i,s,n) for (int i = s; i < n; i++)
......
58 | FOR(k,0,LOG+1) {
| ~~~~~~~~~
sculpture.cpp:58:5: note: in expansion of macro 'FOR'
58 | FOR(k,0,LOG+1) {
| ^~~
sculpture.cpp: In function 'void lolbruh()':
sculpture.cpp:86:25: warning: iteration 41 invokes undefined behavior [-Waggressive-loop-optimizations]
86 | ans += cur*res[k];
| ~~~~~^
sculpture.cpp:10:38: note: within this loop
10 | #define FOR(i,s,n) for (int i = s; i < n; i++)
......
85 | FOR(k,0,LOG+1) {
| ~~~~~~~~~
sculpture.cpp:85:5: note: in expansion of macro 'FOR'
85 | FOR(k,0,LOG+1) {
| ^~~
# | 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... |