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>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define vl vector<ll>
#define fi first
#define se second
#define in insert
#define all(v) v.begin(), v.end()
#define bpc(x) __builtin_popcount(x)
#define endl "\n"
using namespace std;
const int sz = 2005; /// mind the sz
const ll inf = 1e18;
// using namespace __gnu_pbds;
// tree <ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> rbt;
ll n, A, B, pr[sz], a[sz], ca;
ll dp[sz][sz], DP[sz];
bool rec(ll idx, ll blocks, ll bt){
if(idx == (n + 1)){
return (A <= blocks && blocks <= B);
}
if(dp[idx][blocks] != -1){return dp[idx][blocks];}
for(int j = idx + 1; j <= (n + 1); j++){
ll t = (pr[j - 1] - pr[idx - 1]);
if(((ca | t) >> bt << bt) == ca && rec(j, blocks + 1, bt)){
return dp[idx][blocks] = 1;
}
}
return dp[idx][blocks] = 0;
}
bool solveforaequalto1(ll bt){
ll i, j, ra;
vl DP(n + 1, inf);
DP[0] = 0;
for(i = 1; i <= n; i++){
for(j = i; j > 0; j--){
ra = pr[i] - pr[j - 1];
if((ca | ra) >> bt << bt == ca){
DP[i] = min(DP[i], DP[j - 1] + 1);
}
}
}
return DP[n] > B;
}
void solve(){
ll i, j;
cin >> n >> A >> B;
for(i = 1; i <= n; i++){
cin >> a[i];
pr[i] = pr[i - 1] + a[i];
}
for(i = 60; i >= 0; i--){
// cout << i << ' ' << rec(1, 0, i) << endl;
if(A == 1){
ca |= (solveforaequalto1(i)) * (1ll << i);
}
else{
memset(dp, -1, sizeof(dp));
ca |= (!rec(1, 0, i)) * (1ll << i);
}
}
cout << ca << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin >> t;
while(t--){
solve();
}
}
/*
6 1 3
8 1 2 1 5 4
*/
Compilation message (stderr)
sculpture.cpp: In function 'bool rec(long long int, long long int, long long int)':
sculpture.cpp:31:36: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
31 | return dp[idx][blocks] = 1;
| ~~~~~~~~~~~~~~~~^~~
sculpture.cpp:34:28: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
34 | return dp[idx][blocks] = 0;
| ~~~~~~~~~~~~~~~~^~~
sculpture.cpp: In function 'void solve()':
sculpture.cpp:51:11: warning: unused variable 'j' [-Wunused-variable]
51 | ll i, j;
| ^
# | 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... |