#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=1e18;
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;
for (int j=0;j<a.size();j++)
{
if (cur==10) b.push_back(0),cur=0;
int tp=a[j];
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;
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:30:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=0;j<a.size();j++)
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2020 KB |
Output is correct |
2 |
Correct |
0 ms |
2020 KB |
Output is correct |
3 |
Correct |
0 ms |
2020 KB |
Output is correct |
4 |
Correct |
0 ms |
2020 KB |
Output is correct |
5 |
Correct |
0 ms |
2020 KB |
Output is correct |
6 |
Incorrect |
0 ms |
2020 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2020 KB |
Output is correct |
2 |
Correct |
0 ms |
2020 KB |
Output is correct |
3 |
Correct |
0 ms |
2020 KB |
Output is correct |
4 |
Correct |
0 ms |
2020 KB |
Output is correct |
5 |
Correct |
0 ms |
2020 KB |
Output is correct |
6 |
Incorrect |
0 ms |
2020 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2020 KB |
Output is correct |
2 |
Correct |
36 ms |
2160 KB |
Output is correct |
3 |
Correct |
26 ms |
2160 KB |
Output is correct |
4 |
Incorrect |
26 ms |
2160 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2020 KB |
Output is correct |
2 |
Correct |
0 ms |
2020 KB |
Output is correct |
3 |
Correct |
0 ms |
2020 KB |
Output is correct |
4 |
Correct |
0 ms |
2020 KB |
Output is correct |
5 |
Correct |
123 ms |
2528 KB |
Output is correct |
6 |
Correct |
0 ms |
2020 KB |
Output is correct |
7 |
Incorrect |
0 ms |
2020 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |