# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
76812 | 2018-09-18T11:52:36 Z | vex | Bali Sculptures (APIO15_sculpture) | C++14 | 2 ms | 720 KB |
#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<=b)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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Incorrect | 2 ms | 408 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 536 KB | Output is correct |
2 | Correct | 2 ms | 592 KB | Output is correct |
3 | Incorrect | 2 ms | 592 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 592 KB | Output is correct |
2 | Correct | 2 ms | 592 KB | Output is correct |
3 | Incorrect | 2 ms | 592 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 592 KB | Output is correct |
2 | Correct | 2 ms | 592 KB | Output is correct |
3 | Incorrect | 2 ms | 592 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 592 KB | Output is correct |
2 | Correct | 2 ms | 720 KB | Output is correct |
3 | Incorrect | 2 ms | 720 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |