Submission #946538

#TimeUsernameProblemLanguageResultExecution timeMemory
946538amirhoseinfar1385Bali Sculptures (APIO15_sculpture)C++17
100 / 100
56 ms600 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2") #include<bits/stdc++.h> using namespace std; const long long maxn=2000+10,lg=45; long long n,l,r,all[maxn],mainres; void vorod(){ cin>>n>>l>>r; for(long long i=1;i<=n;i++){ cin>>all[i]; } } long long check2(long long f){ vector<long long>dp(n+1); dp[0]=0; for(long long i=1;i<=n;i++){ dp[i]=n+2; long long sum=0; for(long long j=i;j>=1;j--){ sum+=all[j]; if(sum&f){ continue; } dp[i]=min(dp[i],dp[j-1]+1); } } 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(); 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...