#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);
}
Compilation message
sequence.cpp: In function 'long long int back_track(vii, int)':
sequence.cpp:12:14: warning: overflow in implicit constant conversion [-Woverflow]
long long m=1e19;
^
sequence.cpp:30:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=0;j<a.size();j++)
^
sequence.cpp:34:19: error: 'y' was not declared in this scope
if (a[i]&1 and y==0) z=1;
^