This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
Solution for APIO 2015 - Bali Sculpture
Tags :
*/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define fi first
#define se second
ll MOD = 1000000007;
ll power(ll base, ll n){
if (n == 0) return 1;
if (n == 1) return base;
ll halfn = power(base, n/2);
if (n % 2 == 0) return (halfn * halfn) % MOD;
return (((halfn * halfn) % MOD) * base) % MOD;
}
ll inverse(ll n){
return power(n, MOD-2);
}
ll add(ll a, ll b){
return (a+b) % MOD;
}
ll mul(ll a, ll b){
a %= MOD;
return (a*b) % MOD;
}
ll gcd(ll a, ll b){
if (a == 1) return 1;
if (a == 0) return b;
return gcd(b%a, a);
}
void solve(){
int n, a, b; cin >> n >> a >> b;
vector<ll> y(n+1); FOR(i,1,n+1) cin >> y[i];
vector<ll> p(n+1); FOR(i,1,n+1) p[i] = p[i-1] + y[i];
ll maxi = 1; int max_bit = 0;
while (maxi <= p[n]){
max_bit++;
maxi *= 2;
}
max_bit--;
if (a==1){
int mat[n+1][n+2];
ms(mat, 0, sizeof(mat));
FOR(i,1,n+1){
FOR(j,i+1,n+2){
mat[i][j]=1;
}
}
ll cur = 0;
ROF(i,max_bit,0){
cur += (ll) (1<<i);
FOR(i,1,n+1){
FOR(j,i+1,n+2){
ll val = p[j-1]-p[i-1];
if (val&cur){
mat[i][j]=0;
}
}
}
vi dp(n+2, MOD);
dp[1]=0;
FOR(i,1,n+1){
FOR(j,i+1,n+2){
if (mat[i][j] == 1 && dp[i] != MOD){
dp[j]=min(dp[j],dp[i]+1);
}
}
}
if (dp[n+1] > b){
cur -= (ll) (1<<i);
}
FOR(i,1,n+1){
FOR(j,i+1,n+2){
mat[i][j]=1;
}
}
}
cout << (1<<(max_bit+1)) - 1 - cur;
}
}
int main() {
ios::sync_with_stdio(false);
int TC = 1;
//cin >> TC;
FOR(i, 1, TC+1){
//cout << "Case #" << i << ": ";
solve();
}
}
Compilation message (stderr)
sculpture.cpp:10: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
10 | #pragma GCC optimization ("Ofast")
|
sculpture.cpp:11: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
11 | #pragma GCC optimization ("unroll-loops")
|
# | 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... |