#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define inf 1000000010
ll solve(vector<int> need, int depth) {
if (depth > 12) return -1;
if (need.size() == 1) {
ll ans = 0;
F0R(i, 10) {
int j = i;
if (i == 0) j = 1;
else if (i == 1) j = 0;
if (need[0] & (1 << j)) {
ans = ans*10+j;
}
}
return ans;
}
ll ans = -1;
F0R(lastDigit, 10) {
vector<int> next;
int curDigit = lastDigit;
int curMask = 0;
for (auto x : need) {
curMask |= x & ~(1 << curDigit);
curDigit++;
if (curDigit == 10) {
next.pb(curMask);
curDigit = 0;
curMask = 0;
}
}
if (curDigit != 0) next.pb(curMask);
ll ans2 = solve(next, depth + 1);
if (ans2 == -1) continue;
if (ans == -1 || ans2*10+lastDigit < ans) {
ans = ans2*10+lastDigit;
}
}
return ans;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int k; cin >> k;
vector<int> A;
F0R(i, k) {
int x; cin >> x;
A.pb(1 << x);
}
cout << solve(A, 1) << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Incorrect |
1 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |