#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 (v[0] & 1) {
ans *= 10;
v[0] -= 1;
}
}
}
if (ans == 0 && (v[0] & 1)) {
ans = 10;
}
return ans;
} else {
ll ans = 1e15;
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 (v[i] & 1)
zero = 1;
if (j == 9 || i + 1 == sz(v)) {
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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |