# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
705508 | Alihan_8 | Bali Sculptures (APIO15_sculpture) | C++17 | 247 ms | 460 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.
#include <bits/stdc++.h>
// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
// define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define mpr make_pair
#define ln '\n'
void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define int long long
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, A, B; cin >> n >> A >> B;
vector <int> p(n), pref(n+1);
for ( auto &i: p ) cin >> i;
for ( int i = 1; i <= n; i++ ){
pref[i] = pref[i-1]+p[i-1];
}
auto ok = [&](int K, int f, int bit){
return (f >> bit | K) == K;
};
if ( A == 1 ){
int ans = 0;
for ( int bit = 63; bit >= 0; bit-- ){
vector <int> dp(n+1, n+1);
dp[0] = 0;
for ( int i = 1; i <= n; i++ ){
for ( int j = 0; j < i; j++ ){
if ( !ok(ans, pref[i]-pref[j], bit) ) continue;
dp[i] = min(dp[i], dp[j]+1);
}
}
ans |= dp.back() > B;
ans <<= 1;
}
cout << ans/2 << ln;
return 0;
}
int ans = 0;
for ( int bit = 63; bit >= 0; bit-- ){
vector <vector<int>> dp(n+1, vector <int> (n+1));
dp[0][0] = true;
for ( int k = 1; k <= n; k++ ){
for ( int i = 1; i <= n; i++ ){
for ( int j = 0; j < i; j++ ){
if ( !ok(ans, pref[i]-pref[j], bit) ) continue;
dp[i][k] |= dp[j][k-1];
}
}
}
bool flag = false;
for ( int i = A; i <= B; i++ ){
flag |= dp[n][i];
}
ans += !flag;
ans <<= 1;
}
cout << ans/2;
cout << '\n';
}
/*
6 2 3
8 1 2 1 5 4
*/
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... |