# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
136144 | forelax | Sequence (BOI14_sequence) | C++14 | 129 ms | 888 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |