#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
#define pb push_back
#define sz(v) ((int)(v).size())
typedef long long lld;
int N;
int A[MAXN];
lld ans = 12345678900000;
void dfs(lld n, lld v, vector<int> &arr)
{
if (arr.empty()){ ans = v; return; }
if (v+n >= ans) return;
for (int i=9;i>=0;i--){
lld m = v + n*i;
if (m >= ans) continue;
vector <int> nxt;
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.pb(p);
}
if (sz(arr) == sz(nxt)) continue;
dfs(n*10, m, nxt);
}
}
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);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2112 KB |
Output is correct |
2 |
Execution timed out |
1000 ms |
2108 KB |
Program timed out |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2112 KB |
Output is correct |
2 |
Execution timed out |
1000 ms |
2108 KB |
Program timed out |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
2112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2112 KB |
Output is correct |
2 |
Execution timed out |
1000 ms |
2108 KB |
Program timed out |
3 |
Halted |
0 ms |
0 KB |
- |