#include <stdio.h>
#include <vector>
using namespace std;
long long findN(vector<int> in, int sum)
{
long long res = 1e18;
bool good = false;
for (int p : in) if (p) good = true;
if (!good) return (sum == 0) ? 1 : 0;
if (in.size() == 1){
res = 0;
int x=0;
if (in[0] & 1){
res = 1;
for (x++;x<=9;x++) if (in[0] & (1 << x)){
res = x; break;
}
res *= 10;
}
for (x++;x<=9;x++) if (in[0] & (1 << x)){
res = res * 10 + x;
}
}
else{
for (int x=0;x<=9;x++){
vector<int> reduce;
for (int i=0,v=x;i<in.size();i++){
if (i == 0 || v == 0) reduce.push_back(0);
int h = in[i];
if (h & (1 << v)) h ^= (1 << v);
reduce.back() |= h;
if (++v == 10) v = 0;
}
if (in != reduce){
long long g = findN(reduce,sum+x) * 10 + x;
if (g == 0 && (sum == 0 || in[0] & 1)) continue;
if (res > g)
res = g;
}
}
}
return res;
}
int main()
{
vector<int> input;
int N,x; scanf ("%d",&N); while (N--){
scanf ("%d",&x);
input.push_back(1<<x);
}
printf ("%lld\n",findN(input,0));
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1236 KB |
Output is correct |
2 |
Correct |
0 ms |
1236 KB |
Output is correct |
3 |
Correct |
0 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
1236 KB |
Output is correct |
5 |
Correct |
0 ms |
1236 KB |
Output is correct |
6 |
Correct |
0 ms |
1236 KB |
Output is correct |
7 |
Correct |
0 ms |
1236 KB |
Output is correct |
8 |
Correct |
0 ms |
1236 KB |
Output is correct |
9 |
Correct |
0 ms |
1236 KB |
Output is correct |
10 |
Correct |
0 ms |
1236 KB |
Output is correct |
11 |
Correct |
0 ms |
1236 KB |
Output is correct |
12 |
Correct |
0 ms |
1236 KB |
Output is correct |
13 |
Correct |
0 ms |
1236 KB |
Output is correct |
14 |
Correct |
0 ms |
1236 KB |
Output is correct |
15 |
Correct |
0 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1236 KB |
Output is correct |
2 |
Correct |
0 ms |
1236 KB |
Output is correct |
3 |
Correct |
0 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
1236 KB |
Output is correct |
5 |
Correct |
0 ms |
1236 KB |
Output is correct |
6 |
Correct |
0 ms |
1236 KB |
Output is correct |
7 |
Correct |
0 ms |
1236 KB |
Output is correct |
8 |
Correct |
0 ms |
1236 KB |
Output is correct |
9 |
Correct |
0 ms |
1236 KB |
Output is correct |
10 |
Correct |
0 ms |
1236 KB |
Output is correct |
11 |
Correct |
0 ms |
1236 KB |
Output is correct |
12 |
Correct |
0 ms |
1236 KB |
Output is correct |
13 |
Correct |
0 ms |
1236 KB |
Output is correct |
14 |
Correct |
0 ms |
1236 KB |
Output is correct |
15 |
Correct |
0 ms |
1236 KB |
Output is correct |
16 |
Correct |
0 ms |
1236 KB |
Output is correct |
17 |
Correct |
0 ms |
1236 KB |
Output is correct |
18 |
Correct |
0 ms |
1236 KB |
Output is correct |
19 |
Correct |
0 ms |
1236 KB |
Output is correct |
20 |
Correct |
0 ms |
1236 KB |
Output is correct |
21 |
Correct |
0 ms |
1236 KB |
Output is correct |
22 |
Correct |
0 ms |
1236 KB |
Output is correct |
23 |
Correct |
0 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1236 KB |
Output is correct |
2 |
Correct |
32 ms |
1236 KB |
Output is correct |
3 |
Correct |
32 ms |
1236 KB |
Output is correct |
4 |
Correct |
32 ms |
1236 KB |
Output is correct |
5 |
Correct |
32 ms |
1236 KB |
Output is correct |
6 |
Correct |
8 ms |
1236 KB |
Output is correct |
7 |
Correct |
132 ms |
2024 KB |
Output is correct |
8 |
Correct |
128 ms |
1676 KB |
Output is correct |
9 |
Correct |
180 ms |
2144 KB |
Output is correct |
10 |
Correct |
176 ms |
2144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1236 KB |
Output is correct |
2 |
Correct |
0 ms |
1236 KB |
Output is correct |
3 |
Correct |
0 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
1236 KB |
Output is correct |
5 |
Correct |
152 ms |
1668 KB |
Output is correct |
6 |
Correct |
0 ms |
1236 KB |
Output is correct |
7 |
Correct |
0 ms |
1236 KB |
Output is correct |
8 |
Correct |
0 ms |
1236 KB |
Output is correct |
9 |
Correct |
0 ms |
1236 KB |
Output is correct |
10 |
Correct |
0 ms |
1236 KB |
Output is correct |
11 |
Correct |
176 ms |
2144 KB |
Output is correct |
12 |
Correct |
296 ms |
2144 KB |
Output is correct |
13 |
Correct |
0 ms |
1236 KB |
Output is correct |
14 |
Correct |
4 ms |
1236 KB |
Output is correct |
15 |
Correct |
0 ms |
1236 KB |
Output is correct |
16 |
Correct |
0 ms |
1236 KB |
Output is correct |
17 |
Correct |
0 ms |
1236 KB |
Output is correct |
18 |
Correct |
0 ms |
1236 KB |
Output is correct |
19 |
Correct |
0 ms |
1236 KB |
Output is correct |
20 |
Correct |
0 ms |
1236 KB |
Output is correct |
21 |
Correct |
0 ms |
1236 KB |
Output is correct |
22 |
Correct |
0 ms |
1236 KB |
Output is correct |
23 |
Correct |
0 ms |
1236 KB |
Output is correct |
24 |
Correct |
0 ms |
1236 KB |
Output is correct |
25 |
Correct |
0 ms |
1236 KB |
Output is correct |
26 |
Correct |
4 ms |
1236 KB |
Output is correct |
27 |
Correct |
32 ms |
1236 KB |
Output is correct |
28 |
Correct |
32 ms |
1236 KB |
Output is correct |
29 |
Correct |
28 ms |
1236 KB |
Output is correct |
30 |
Correct |
32 ms |
1236 KB |
Output is correct |
31 |
Correct |
12 ms |
1236 KB |
Output is correct |
32 |
Correct |
124 ms |
2024 KB |
Output is correct |
33 |
Correct |
132 ms |
1676 KB |
Output is correct |
34 |
Correct |
176 ms |
2144 KB |
Output is correct |
35 |
Correct |
176 ms |
2144 KB |
Output is correct |
36 |
Correct |
232 ms |
2036 KB |
Output is correct |
37 |
Correct |
316 ms |
2136 KB |
Output is correct |
38 |
Correct |
192 ms |
1720 KB |
Output is correct |
39 |
Correct |
324 ms |
2144 KB |
Output is correct |
40 |
Correct |
324 ms |
2144 KB |
Output is correct |