Submission #365140

#TimeUsernameProblemLanguageResultExecution timeMemory
365140YJUBali Sculptures (APIO15_sculpture)C++14
100 / 100
222 ms31980 KiB
#include<bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector,Ofast") using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; const ll MOD=1e9+7; const ll MOD2=998244353; const ll N=2e3+5; const ld pi=acos(-1); const ll INF=(1LL<<60); #define SQ(i) ((i)*(i)) #define REP(i,n) for(ll i=0;i<n;i++) #define REP1(i,n) for(ll i=1;i<=n;i++) #define pb push_back #define mp make_pair #define X first #define Y second #define setp setprecision #define lwb lower_bound #define SZ(_a) (ll)_a.size() ll n,a,b,u[N],v[N][N]; bool oka(ll k){ memset(v,0,sizeof(v)); v[0][0]=1; for(int i=1;i<=n;i++){ for(int j=1;j<=b&&j<=i;j++){ v[i][j]=0; for(int g=1;g<=i;g++){ //cout<<i-g<<"\n"; if(((u[i]-u[i-g])|k)<=k&&v[i-g][j-1]==1)v[i][j]=1; } } } for(int i=a;i<=b;i++)if(v[n][i])return 1; return 0; } bool okb(ll k){ ll f[N]; f[0]=0; for(int i=1;i<=n;i++){ f[i]=INF; for(int j=1;j<=i;j++){ if(((u[i]-u[i-j])|k)<=k)f[i]=min(f[i],f[i-j]+1); } } return (f[n]<=b); } void solvea(){ ll bit=(1LL<<41)-1; for(int i=40;i>=0;i--){ if(oka(bit^(1LL<<i)))bit^=(1LL<<i); } cout<<bit<<"\n"; } void solveb(){ ll bit=(1LL<<41)-1; for(int i=40;i>=0;i--){ if(okb(bit^(1LL<<i)))bit^=(1LL<<i); } cout<<bit<<"\n"; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>a>>b; REP1(i,n)cin>>u[i],u[i]+=u[i-1]; if(a==1){ solveb(); }else{ solvea(); } return 0; } /* 6 2 3 8 1 2 1 5 4 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...