#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
typedef long long lld;
int N;
int A[MAXN];
lld ans = 12345678900000;
void dfs(lld n, lld v, vector<int> &arr)
{
if (v+n >= ans) return;
if (arr.empty()){ ans = v; return; }
vector <int> nxt[10];
for (int i=0;i<10;i++){
lld m = v + i*n;
for (int p: arr){
lld now = m + p;
bool sw = 0;
for (lld tmp=now;tmp;tmp/=10) if (tmp%10 == A[p]){ sw = 1; break; }
if (!sw) nxt[i].pb(p);
}
}
vector <int> tmp;
for (int i=0;i<10;i++) tmp.pb(i);
sort(all(tmp), [nxt](const int &a, const int &b){
return sz(nxt[a]) < sz(nxt[b]);
});
for (int d: tmp){
if (sz(nxt[d]) == sz(arr)) break;
dfs(n*10, v + d*n, nxt[d]);
}
}
int main()
{
scanf("%d", &N);
for (int i=0;i<N;i++) scanf("%d", A+i);
vector <int> tmp;
for (int i=0;i<N;i++) tmp.pb(i);
dfs(1, 0, tmp);
printf("%lld\n", ans);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2124 KB |
Output is correct |
2 |
Correct |
14 ms |
2252 KB |
Output is correct |
3 |
Correct |
0 ms |
2124 KB |
Output is correct |
4 |
Correct |
9 ms |
2124 KB |
Output is correct |
5 |
Correct |
0 ms |
2124 KB |
Output is correct |
6 |
Correct |
0 ms |
2124 KB |
Output is correct |
7 |
Correct |
14 ms |
2124 KB |
Output is correct |
8 |
Incorrect |
173 ms |
2384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2124 KB |
Output is correct |
2 |
Correct |
14 ms |
2252 KB |
Output is correct |
3 |
Correct |
0 ms |
2124 KB |
Output is correct |
4 |
Correct |
7 ms |
2124 KB |
Output is correct |
5 |
Correct |
0 ms |
2124 KB |
Output is correct |
6 |
Correct |
0 ms |
2124 KB |
Output is correct |
7 |
Incorrect |
368 ms |
2384 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
2124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2124 KB |
Output is correct |
2 |
Correct |
10 ms |
2252 KB |
Output is correct |
3 |
Correct |
0 ms |
2124 KB |
Output is correct |
4 |
Correct |
6 ms |
2124 KB |
Output is correct |
5 |
Execution timed out |
1000 ms |
11204 KB |
Program timed out |
6 |
Halted |
0 ms |
0 KB |
- |