Submission #12030

#TimeUsernameProblemLanguageResultExecution timeMemory
12030dohyun0324Sequence (BOI14_sequence)C++98
100 / 100
304 ms2016 KiB
#include<stdio.h> #include<vector> using namespace std; int sw,n; long long int dap=2147483647000000000000LL,c; void dfs(long long int num,vector<int>a,int n,long long int w) { int i,j; if(w>=10000000) return; if(n==-1) { if(num<w) num+=w*10; if(num==0) num=w*10; if(dap>num) dap=num; return; } if(num+w>=dap) return; if(n==1) { c=0; for(i=1;i<=9;i++) { if((1<<i)&a[0]) { c=c*10+i; if(c<10 && 1&a[0]) c=c*10; } } if(a[0]==1) c=10; if(c>dap/w) return; c*=w; c+=num; if(c==0) c=w*10; if(dap>c) { dap=c; } return; } for(i=0;i<=9;i++) { vector<int>s((i+n-1)/10+1); sw=0; for(j=0;j<n;j++) { s[(i+j)/10]|=a[j]&(1023-(1<<((i+j)%10))); if(s[(i+j)/10]) sw=1; } if(i==0 && a[0]==0 && sw==0) { if(dap>num) dap=num; break; } if(sw==0){dfs(i*w+num,s,-1,w); break;} dfs(i*w+num,s,(i+n-1)/10+1,w*10); } } int main() { int i; scanf("%d",&n); vector<int>a(n); for(i=0;i<n;i++){ scanf("%d",&a[i]); a[i]=(1<<a[i]); } dfs(0,a,n,1); printf("%lld",dap); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...