#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (ll)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 1e3 + 10;
ll cal(vector <int> v, int is) {
if (sz(v) == 1) {
ll ans = 0;
for (int i = 1; i <= 9; i++) {
if (v[0] & (1 << i))
ans = ans * 10 + i;
}
if (ans == 0 && v[0] & 1)
ans = 10;
return ans;
} else {
ll ans = 1e18;
for (int dig = 0; dig <= 9 - is; dig++) {
vector <int> nxt;
int j = dig, mask = 0, zero = 0;
for (int i = 0; i < sz(v); i++) {
int cur = v[i];
if (cur & (1 << j)) {
cur ^= (1 << j);
}
mask |= cur;
if (cur & 1)
zero = 1;
if (j == 9 || i == sz(v) - 1) {
nxt.pb(mask);
mask = 0;
}
j = (j + 1) % 10;
}
ll tt = cal(nxt, sz(v) == 2 && dig == 9) * 10 + dig;
if (tt == 0 && zero) {
tt = 10;
}
ans = min(ans, tt);
}
return ans;
}
return -1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector <int> v(n);
for (auto &x : v) {
cin >> x;
x = (1 << x);
}
cout << cal(v, 0) << '\n';
return 0;
}
/*
x + s
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
448 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
12 ms |
348 KB |
Output is correct |
3 |
Correct |
12 ms |
344 KB |
Output is correct |
4 |
Incorrect |
13 ms |
564 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
49 ms |
852 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |