Submission #946565

#TimeUsernameProblemLanguageResultExecution timeMemory
946565amirhoseinfar1385Bali Sculptures (APIO15_sculpture)C++17
100 / 100
69 ms604 KiB
#include<bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2") using namespace std; const long long maxn=2000+10,lg=45; long long n,l,r,all[maxn],mainres,ps[maxn]; void vorod(){ cin>>n>>l>>r; for(long long i=1;i<=n;i++){ cin>>all[i]; } } long long check2(long long f){ vector<int>dp(n+1); dp[0]=0; for(long long i=1;i<=n;i++){ dp[i]=n+2; long long x=ps[i]; for(int j=0;j<i;j++){ ps[j]=x-ps[j]; } for(long long j=0;j<i;j++){ dp[i]=(ps[j]&f)?dp[i]:min(dp[i],dp[j]+1); } for(int j=0;j<i;j++){ ps[j]=-ps[j]+x; } } return dp[n]<=r; } long long check1(long long f){ vector<vector<char>>dp(n+1,vector<char>(n+1)); dp[0][0]=1; for(long long i=1;i<=n;i++){ for(int h=1;h<=r;h++){ long long suma=0; for(int j=i;j>=1;j--){ suma+=all[j]; if(suma&f){ continue; } if(dp[j-1][h-1]){ dp[i][h]=1; break; } } } } for(long long i=l;i<=r;i++){ if(dp[n][i]==1){ return 1; } } return 0; } void solve1(){ long long fix=0; for(long long i=lg-1;i>=0;i--){ fix+=(1ll<<i); if(!check1(fix)){ fix-=(1ll<<i); } } mainres=(1ll<<lg)-1-fix; } void solve2(){ long long fix=0; for(long long i=lg-1;i>=0;i--){ fix+=(1ll<<i); if(!check2(fix)){ fix-=(1ll<<i); } } mainres=(1ll<<lg)-1-fix; } void khor(){ cout<<mainres<<"\n"; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("inp.txt","r",stdin); vorod(); for(int i=1;i<=n;i++){ ps[i]=all[i]+ps[i-1]; } if(l>1){ solve1(); }else{ solve2(); } khor(); }
#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...