# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
243971 | TadijaSebez | Sequence (BOI14_sequence) | C++11 | 241 ms | 1520 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;
#define ll long long
#define pb push_back
ll Solve(vector<int> v,int sub=0){
if(v.size()==1){
if(v[0]==0)return 0;
ll ans=0;
for(int i=1;i<=9;i++){
if(v[0]>>i&1){
ans=ans*10+i;
if(v[0]&1)ans*=10,v[0]--;
}
}
if(v[0]&1)ans=10;
return ans;
}else{
ll ans=1e18;
for(int las=0;las<=9-sub;las++){
vector<int> tmp;
int all=0,zr=0;
for(int i=0,j=las;i<v.size();i++,j=(j+1)%10){
if(i&&!j)tmp.pb(all),all=0;
if(!j&&(v[i]&1))zr=1;
all|=v[i]&(~(1<<j));
}
tmp.pb(all);
ll now=Solve(tmp,v.size()<=2&&las==9)*10+las;
if(zr&&!now)now=10;
ans=min(ans,now);
}
return ans;
}
}
int main(){
int n;scanf("%i",&n);
vector<int> v;
for(int i=1,j;i<=n;i++)scanf("%i",&j),v.pb(1<<j);
printf("%lld\n",Solve(v));
return 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... |