//
// main.cpp
// 32
//
// Created by KJBS2 on 2014. 11. 18..
// Copyright (c) 2014년 KJBS2. All rights reserved.
//
#include <stdio.h>
#define MAXN 101101
typedef long long ll;
int N;
int Nr[MAXN];
void INPUT() {
scanf("%d", &N);
for(int i=0; i<N; i++) {
int x; scanf("%d", &x);
Nr[i] = (1 << x);
}
return;
}
ll Get(int Now[], int n, int pp) {
if(n==1) {
ll ans = 0;
bool iszero = false;
if( (Now[0] >> 0) % 2 == 1 )
iszero = true;
if(!iszero) {
for(int i=1; i<10; i++) {
if( (Now[0] >> i) % 2 == 1 ) {
ans *= 10;
ans += i;
}
}
return ans;
}else{
int p = -1;
for(int i=1; i<10; i++)
if( (Now[0] >> i) % 2 == 1 ) {
p = i;
break;
}
if(p == -1) return 10;
ans = p * 10;
for(int i=p+1; i<10; i++) {
if( (Now[0] >> i) % 2 == 1 ) {
ans *= 10;
ans += i;
}
}
}
}
if(pp>5) {
ll ans = 0;
bool iszero = false;
for(int j=0; j<n; j++)
if( (Now[j] >> 0) % 2 == 1 )
iszero = true;
if(!iszero) {
for(int i=1; i<10; i++) {
for(int j=0; j<n; j++) {
if( (Now[j] >> i) % 2 == 1 ) {
ans *= 10;
ans += i;
}
}
}
return ans;
}else{
int p = -1;
for(int i=1; i<10; i++) {
for(int j=0; j<n; j++)
if( (Now[j] >> i) % 2 == 1 ) {
p = i;
break;
}
if(p != -1) break;
}
if(p == -1) return 10;
ans = p * 10;
for(int i=p+1; i<10; i++) {
for(int j=0; j<n; j++) {
if( (Now[j] >> i) % 2 == 1 ) {
ans *= 10;
ans += i;
}
}
}
}
return ans;
}
int *next;
int the_min = MAXN;
next = new int [the_min];
ll ans = (ll)(0x7fffffff) * (ll)(0x7fffffff);
for(int i=0; i<10; i++) {
int nextn = 0;
bool empty = true;
bool zz = true;
int first = 0;
for(int j=0; j<10-i && j<n; j++) {
int p = i+j;
int now = Now[j];
if( (Now[j] >> p) % 2 == 1 ) {
now -= (1 << p);
if(p == 0) zz = false;
}
first = (first | now);
}
if(first != 0) empty = false;
next[nextn++] = first;
int t = 10-i;
for(int j=t; j<n; j+=10) {
int first = 0;
for(int k=0; k<10 && j+k<n; k++) {
int now = Now[j+k];
if( (Now[j+k] >> k) % 2 == 1 ) {
now -= (1 << k);
if(k == 0) zz = false;
}
first = (first | now);
}
if(first != 0) empty = false;
next[nextn++] = first;
}
if(pp==0) {
// printf("%d %d\n", i, nextn);
}
ll get = 0;
if(empty == false)
get = Get(next, nextn, pp+1);
ll nowi = get * 10 + i;
if(get == 0 && i == 0 && zz == false) {
nowi = 10;
}
if(ans > nowi)
ans = nowi;
if(pp==0) {
// printf(">%d %lld\n", i, nowi);
}
}
delete [] next;
return ans;
}
int main() {
INPUT();
printf("%lld", Get(Nr, N, 0) );
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3972 KB |
Output is correct |
2 |
Correct |
120 ms |
3972 KB |
Output is correct |
3 |
Correct |
116 ms |
3972 KB |
Output is correct |
4 |
Correct |
112 ms |
3972 KB |
Output is correct |
5 |
Correct |
72 ms |
3972 KB |
Output is correct |
6 |
Correct |
64 ms |
3972 KB |
Output is correct |
7 |
Correct |
4 ms |
3972 KB |
Output is correct |
8 |
Correct |
72 ms |
3972 KB |
Output is correct |
9 |
Correct |
0 ms |
1600 KB |
Output is correct |
10 |
Correct |
92 ms |
3972 KB |
Output is correct |
11 |
Correct |
76 ms |
3972 KB |
Output is correct |
12 |
Correct |
72 ms |
3972 KB |
Output is correct |
13 |
Correct |
108 ms |
3972 KB |
Output is correct |
14 |
Correct |
96 ms |
3972 KB |
Output is correct |
15 |
Correct |
92 ms |
3972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3972 KB |
Output is correct |
2 |
Correct |
92 ms |
3972 KB |
Output is correct |
3 |
Correct |
92 ms |
3972 KB |
Output is correct |
4 |
Correct |
96 ms |
3972 KB |
Output is correct |
5 |
Correct |
64 ms |
3972 KB |
Output is correct |
6 |
Correct |
52 ms |
3972 KB |
Output is correct |
7 |
Correct |
4 ms |
3972 KB |
Output is correct |
8 |
Correct |
4 ms |
3972 KB |
Output is correct |
9 |
Correct |
40 ms |
3972 KB |
Output is correct |
10 |
Correct |
0 ms |
1600 KB |
Output is correct |
11 |
Correct |
84 ms |
3972 KB |
Output is correct |
12 |
Correct |
92 ms |
3972 KB |
Output is correct |
13 |
Correct |
92 ms |
3972 KB |
Output is correct |
14 |
Correct |
108 ms |
3972 KB |
Output is correct |
15 |
Correct |
120 ms |
3972 KB |
Output is correct |
16 |
Correct |
64 ms |
3972 KB |
Output is correct |
17 |
Correct |
72 ms |
3972 KB |
Output is correct |
18 |
Correct |
92 ms |
3972 KB |
Output is correct |
19 |
Correct |
124 ms |
3972 KB |
Output is correct |
20 |
Correct |
100 ms |
3972 KB |
Output is correct |
21 |
Correct |
92 ms |
3972 KB |
Output is correct |
22 |
Correct |
80 ms |
3972 KB |
Output is correct |
23 |
Correct |
88 ms |
3972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1600 KB |
Output is correct |
2 |
Correct |
56 ms |
3972 KB |
Output is correct |
3 |
Correct |
56 ms |
3972 KB |
Output is correct |
4 |
Correct |
84 ms |
3972 KB |
Output is correct |
5 |
Correct |
36 ms |
3972 KB |
Output is correct |
6 |
Correct |
40 ms |
3972 KB |
Output is correct |
7 |
Correct |
76 ms |
3972 KB |
Output is correct |
8 |
Correct |
80 ms |
3972 KB |
Output is correct |
9 |
Correct |
152 ms |
3972 KB |
Output is correct |
10 |
Correct |
128 ms |
3972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3972 KB |
Output is correct |
2 |
Correct |
112 ms |
3972 KB |
Output is correct |
3 |
Correct |
100 ms |
3972 KB |
Output is correct |
4 |
Correct |
96 ms |
3972 KB |
Output is correct |
5 |
Correct |
144 ms |
3972 KB |
Output is correct |
6 |
Correct |
68 ms |
3972 KB |
Output is correct |
7 |
Correct |
68 ms |
3972 KB |
Output is correct |
8 |
Correct |
4 ms |
3972 KB |
Output is correct |
9 |
Correct |
4 ms |
3972 KB |
Output is correct |
10 |
Correct |
48 ms |
3972 KB |
Output is correct |
11 |
Correct |
108 ms |
3972 KB |
Output is correct |
12 |
Correct |
92 ms |
3972 KB |
Output is correct |
13 |
Correct |
0 ms |
1600 KB |
Output is correct |
14 |
Correct |
128 ms |
3972 KB |
Output is correct |
15 |
Correct |
60 ms |
3972 KB |
Output is correct |
16 |
Correct |
100 ms |
3972 KB |
Output is correct |
17 |
Correct |
64 ms |
3972 KB |
Output is correct |
18 |
Correct |
104 ms |
3972 KB |
Output is correct |
19 |
Correct |
88 ms |
3972 KB |
Output is correct |
20 |
Correct |
120 ms |
3972 KB |
Output is correct |
21 |
Correct |
100 ms |
3972 KB |
Output is correct |
22 |
Correct |
100 ms |
3972 KB |
Output is correct |
23 |
Correct |
100 ms |
3972 KB |
Output is correct |
24 |
Correct |
104 ms |
3972 KB |
Output is correct |
25 |
Correct |
72 ms |
3972 KB |
Output is correct |
26 |
Correct |
104 ms |
3972 KB |
Output is correct |
27 |
Correct |
68 ms |
3972 KB |
Output is correct |
28 |
Correct |
48 ms |
3972 KB |
Output is correct |
29 |
Correct |
68 ms |
3972 KB |
Output is correct |
30 |
Correct |
72 ms |
3972 KB |
Output is correct |
31 |
Correct |
48 ms |
3972 KB |
Output is correct |
32 |
Correct |
100 ms |
3972 KB |
Output is correct |
33 |
Correct |
84 ms |
3972 KB |
Output is correct |
34 |
Correct |
124 ms |
3972 KB |
Output is correct |
35 |
Correct |
124 ms |
3972 KB |
Output is correct |
36 |
Correct |
164 ms |
3972 KB |
Output is correct |
37 |
Correct |
152 ms |
3972 KB |
Output is correct |
38 |
Correct |
116 ms |
3972 KB |
Output is correct |
39 |
Correct |
156 ms |
3972 KB |
Output is correct |
40 |
Correct |
152 ms |
3972 KB |
Output is correct |