Submission #739512

#TimeUsernameProblemLanguageResultExecution timeMemory
739512Username4132Bali Sculptures (APIO15_sculpture)C++14
100 / 100
192 ms14176 KiB
#include<iostream> #include<vector> #include<random> #include<algorithm> using namespace std; using ll = long long; #define forn(i, n) for(int i=0; i<(int)n; ++i) #define forsn(i, s, n) for(int i=s; i<(int)n; ++i) #define dforn(i, n) for(int i=n-1; i>=0; --i) const int MAXN=2010, INF=1000000000; int n, A, B, arr[MAXN], jump[MAXN][MAXN], dp1[MAXN]; bool dp2[102][102]; bool test(ll bit){ forn(i, n){ ll sum=0; forsn(j, i+1, n+1){ sum+=arr[j-1]; jump[i][j]=((sum|bit)==bit); } } if(A==1){ dp1[n]=0; dforn(i, n){ dp1[i]=INF; forsn(j, i+1, n+1) if(jump[i][j]) dp1[i]=min(dp1[i], dp1[j]+1); } return dp1[0]<=B; } else{ forn(i, B+1) dp2[n][i]=false; forn(i, n) dp2[i][0]=false; dp2[n][0]=true; dforn(i, n) forsn(j, 1, B+1){ dp2[i][j]=false; forsn(k, i+1, n+1) if(jump[i][k]) dp2[i][j]|=dp2[k][j-1]; } bool ans=false; forsn(i, A, B+1) ans|=dp2[0][i]; return ans; } } int main(){ scanf("%d %d %d", &n, &A, &B); bool allzero=true; forn(i, n) scanf("%d", &arr[i]), allzero&=(!arr[i]); if(allzero){ cout << "0\n"; return 0; } ll lo=0, hi=(1LL<<42)-1; while(hi-lo>1){ ll mid=(hi+lo)>>1; if(test(mid)) hi=mid; else lo=mid; } cout << hi << "\n"; }

Compilation message (stderr)

sculpture.cpp: In function 'int main()':
sculpture.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     scanf("%d %d %d", &n, &A, &B);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:48:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     forn(i, n) scanf("%d", &arr[i]), allzero&=(!arr[i]);
      |                ~~~~~^~~~~~~~~~~~~~~
#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...