# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
21871 | petrpan | 수열 (BOI14_sequence) | C++14 | 0 ms | 0 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 <iostream>
#include <vector>
using namespace std;
typedef vector<int> vii;
long long n;
long long back_track(vii a,int al=0)
{
long long m=1e19;
if (a.size()==1)
{
if (!a[0]) return 0;
long long x=0;
for (int i=1;i<=9;i++)
{
if (a[0]&(1<<i)) x*=10,x+=i;
if (x and a[0]&1) x*=10,a[0]^=1;
}
if (!x) x=1;
if (a[0]&1) x*=10;
return x;
}
for (int i=0;i<=9-al;i++)
{
vii b(1,0);
int cur=i,z=0;
for (int j=0;j<a.size();j++)
{
if (cur==10) b.push_back(0),cur=0;
int tp=a[j];
if (a[i]&1 and y==0) z=1;
if (tp&(1<<cur)) tp^=1<<cur;
b.back()|=tp;
cur++;
}
long long tp=back_track(b,(a.size()<=2 and i==9))*10+i;
if (!tp and z) tp=10;
m=min(m,tp);
}
return m;
}
int main()
{
//freopen("input.txt","r",stdin);
cin >> n;
vii x(0);
for (int i=1;i<=n;i++)
{
int d;
cin >> d;
x.push_back(1<<d);
}
cout << back_track(x);
}