Submission #136144

#TimeUsernameProblemLanguageResultExecution timeMemory
136144forelaxSequence (BOI14_sequence)C++14
0 / 100
129 ms888 KiB
#include<bits/stdc++.h> using namespace std; long long ask(vector<int> req,long long pw,long long cn){ // cout<<req.size()<<" "<<pw<<" "<<cn<<endl; if(req.size()==1){ long long num=0; int rq=req[0]; bool first=rq&1; for(int i = 1 ; i < 10 ; i ++){ if(rq&(1<<i)){ num*=10; num+=i; if(first){ num*=10; first=false; } } } if(first)num=10; cn+=num*pw; if(!cn)cn+=pw; return cn; } bool need=false; for(int i = 0 ; i < req.size() ; i ++) if(req[i])need=true; if(!need){ return cn+(cn==0?pw:0); } long long rez=-1; for(int dg=0;dg<10;dg++){ vector<int> treq; bool use=false; for(int i = 0,ng=dg,sw=true ; i < req.size() ; i ++,ng=(ng+1)%10){ if(sw)treq.push_back(0); int rq=req[i]; if(rq&(1<<ng)){ rq-=1<<ng; use=true; } treq.back()|=rq; sw=(ng==9); } if(!use)continue; long long b=ask(treq,pw*10,cn+pw*dg); if(rez==-1||b<rez)rez=b; } return rez; } int main(){ int n; cin>>n; vector<int> v(n); vector<int> req(n); for(int i = 0 ; i < n ; i ++){ cin>>v[i]; req[i]=1<<v[i]; } cout<<ask(req,1,0); }

Compilation message (stderr)

sequence.cpp: In function 'long long int ask(std::vector<int>, long long int, long long int)':
sequence.cpp:25:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0 ; i < req.size() ; i ++)
                     ~~^~~~~~~~~~~~
sequence.cpp:34:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0,ng=dg,sw=true ; i < req.size() ; i ++,ng=(ng+1)%10){
                                       ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...