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>
using namespace std;
//using namespace __gnu_pbds;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define NeedForSpeed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vv vector
#define tut(x) array<int, x>
#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vii;
typedef vector<pii> vpii;
template<class T> bool umin(T& a, const T& b) { return a > b? a = b, true:false; }
template<class T> bool umax(T& a, const T& b) { return a < b? a = b, true:false; }
void usaco(string s) { freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout); }
//template<class T> tree<T,
//less<T>, null_type, rb_tree_tag,
//tree_order_statistics_node_update> ordered_set;
const int N = 2e3+5;
const int mod = 1e9+7;
const ll inf = 1e18;
const ld Pi = acos(-1);
const int B = 500;
#define MULTI 0
int n, m, ans, q, k, res, a[N];
int b, dp[N], pref[N], num;
bool check(int a, int b) { return (((a>>b) | num) == num); }
/*
6 1 3
8 1 2 1 5 4
*/
void solve(int t_case){
cin>>n;
if(n <= 100){
int l, r; cin>>l>>r;
vv<vii> dp(105, vii(105, 0));
for(int i=1;i<=n;i++) cin>>a[i], pref[i] = pref[i-1] + a[i];
for(int b=45;b>=0;b--){
for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) dp[i][j] = 0;
dp[0][0] = 1;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
for(int l=0;l<i;l++){
if(check(pref[i] - pref[l], b)) dp[i][j] |= dp[l][j-1];
}
}
}
bool ok = 1;
for(int i=l;i<=r;i++) if(dp[n][i]) ok = 0;
if(ok) num += 1;
num<<=1;
} num>>=1; cout<<num<<"\n";
} else {
cin>>b, assert(b == 1), cin>>b;
for(int i=1;i<=n;i++) cin>>a[i], pref[i] = pref[i-1] + a[i];
num = 0;
for(int bit=45;bit>=0;bit--){
for(int i=1;i<=n;i++) dp[i] = mod;
for(int i=1;i<=n;i++){
//if(check(pref[i], bit)) dp[i] = 1;
for(int j=0;j<i;j++) if(check(pref[i] - pref[j], bit)) umin(dp[i], dp[j] + 1);
}
if(dp[n] > b) num += 1;
num <<= 1;
} num >>=1; cout<<num<<"\n";\
}
}
signed main(){
NeedForSpeed
if(!MULTI) {
solve(1);
} else {
int t; cin>>t;
for(int t_case = 1; t_case <= t; t_case++) solve(t_case);
} return 0;
}
Compilation message (stderr)
sculpture.cpp: In function 'void usaco(std::string)':
sculpture.cpp:30:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
30 | void usaco(string s) { freopen((s+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:31:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
31 | freopen((s+".out").c_str(),"w",stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |