Submission #76810

#TimeUsernameProblemLanguageResultExecution timeMemory
76810vexBali Sculptures (APIO15_sculpture)C++14
0 / 100
2 ms744 KiB
#include <bits/stdc++.h> #define maxn 2005 using namespace std; int n,a,b; long long s[maxn]; bool moze(int x) { int g=0; int pr=0; long long tr=1LL<<x; for(int i=1;i<=n;i++) { if(s[i]-s[pr]>=tr) { if(i==pr+1)return false; g++; pr=i-1; i--; } else if(i==n)g++; } if(g<=b)return true; return false; } int numbit() { int l=1; int r=50; int sol; while(l<=r) { int mid=(l+r)/2; if(moze(mid)) { sol=mid; r=mid-1; } else l=mid+1; } return sol; } bool t[maxn][maxn]; vector<int>pos[maxn]; bool exist(long long br0,int numb) { long long br=1LL<<numb; for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)t[i][j]=false; for(int i=0;i<=n;i++)pos[i].clear(); pos[0].push_back(0); t[0][0]=true; for(int i=1;i<=n;i++) for(int j=0;j<i;j++) { if(((s[i]-s[j])&br0)==0LL && s[i]-s[j]<br) { for(auto x:pos[j]) { if(!t[i][x+1]) { t[i][x+1]=true; pos[i].push_back(x+1); } } } } /*for(int i=0;i<=n;i++) { cout<<pos[i].size()<<" "; for(auto x:pos[i])cout<<x<<" "; cout<<endl; } cout<<endl<<endl<<endl;*/ for(auto x:pos[n]) { if(a<=x && x<=n)return true; } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin>>n>>a>>b;s[0]=0LL; for(int i=1;i<=n;i++) { int x; cin>>x; s[i]=s[i-1]+x; } int br=numbit(); long long sol=1LL<<(br-1); long long obr=0; for(int i=br-2;i>=0;i--) { obr+=1LL<<i; if(!exist(obr,br)) { obr-=1LL<<i; sol+=1LL<<i; } } cout<<sol<<endl; return 0; } /* 6 1 3 8 1 2 1 5 4 */

Compilation message (stderr)

sculpture.cpp: In function 'int numbit()':
sculpture.cpp:42:12: warning: 'sol' may be used uninitialized in this function [-Wmaybe-uninitialized]
     return sol;
            ^~~
#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...