Submission #48976

#TimeUsernameProblemLanguageResultExecution timeMemory
48976tmwilliamlin168Bali Sculptures (APIO15_sculpture)C++14
100 / 100
105 ms2504 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long inline int in() { int result = 0; char ch = getchar_unlocked(); while (true) { if(ch >= '0' && ch <= '9') break; ch = getchar_unlocked(); } result = ch-'0'; while(true) { ch = getchar_unlocked(); if (ch < '0' || ch > '9') break; result = result*10 + (ch - '0'); } return result; } inline void out(ll x) { ll rev=x; int count = 0; if(x == 0) { putchar_unlocked('0'); putchar_unlocked('\n'); return; } while((rev % 10) == 0) { ++count; rev /= 10; } //obtain the count of the number of 0s rev = 0; while(x != 0) { rev = rev*10 + x % 10; x /= 10; } //store reverse of N in rev while(rev != 0) { putchar_unlocked(rev % 10 + '0'); rev /= 10; } while(count--) putchar_unlocked('0'); putchar_unlocked('\n'); } const int mxN=2000; int n, a, b, dp[mxN+1][mxN+1]; ll y[mxN]; inline bool can(ll x) { if(a>1) memset(dp[0], 0, 4*(b+1)); dp[0][0]=a>1; for(int i=1; i<=n; ++i) { if(a==1) { dp[0][i]=b+1; ll ys=0; for(int j=i-1; j>=0; --j) { ys+=y[j]; if(!(ys&~x)) dp[0][i]=min(dp[0][j]+1, dp[0][i]); } } else { memset(dp[i], 0, 4*(b+1)); ll ys=0; for(int j=i-1; j>=0; --j) { ys+=y[j]; if(!(ys&~x)) for(int k=1; k<=b; ++k) dp[i][k]|=dp[j][k-1]; } } } if(a==1) return dp[0][n]<=b; for(int i=a; i<=b; ++i) if(dp[n][i]) return 1; return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); n=in(), a=in(), b=in(); for(int i=0; i<n; ++i) y[i]=in(); ll ans=(1LL<<41)-1; for(int i=40; i>=0; --i) if(can(ans^(1LL<<i))) ans^=1LL<<i; out(ans); }
#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...