Submission #11185

#TimeUsernameProblemLanguageResultExecution timeMemory
11185gs13068Sequence (BOI14_sequence)C++98
100 / 100
252 ms1980 KiB
#include<cstdio> #include<vector> std::vector<int> a; long long min; void f(int w,std::vector<int> &x,int y,int z,int flag) { if(!w||x.size()==1) { int i,j=0; long long k; for(i=0;i<x.size();i++)j|=x[i]; if(j&1) { for(i=1;i<10;i++)if((j>>i)&1)break; if(i==10)i=1; k=i*10; while(++i<10)if((j>>i)&1)k=k*10+i; } else { k=0; for(i=1;i<10;i++)if((j>>i)&1)k=k*10+i; } if(flag&&!k)k=1; if(k*z+y<min)min=k*z+y; return; } int i,j,k; std::vector<int> t; for(i=0;i<x.size();i++)if(x[i])break; if(i==x.size()) { if(flag)y+=z; if(y<min)min=y; return; } k=0; for(j=0;j<x.size();j++) { if(!j)k|=x[j]; else k|=x[j]&~(1<<(j%10)); if(j%10==9) { t.push_back(k); k=0; } } if(j%10)t.push_back(k); f(w-1,t,y,z*10,flag); for(i=0;i<10;i++) { t.clear(); k=0; for(j=0;j<x.size();j++) { k|=x[j]&~(1<<((i+j)%10)); if((i+j)%10==9) { t.push_back(k); k=0; } } if((i+j)%10)t.push_back(k); f(w-1,t,y+i*z,z*10,i==0); } } int main() { int i,n,t; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&t); a.push_back(1<<t); } for(i=1;n;i++)n/=10; min=1e18; f(i,a,0,1,0); printf("%lld",min); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...