This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5 + 10, num = 1e5;
int K, arr[MX];
inline int check(int a, const int& b){
while(a){
if(a % 10 == b) return true;
a /= 10;
}
return false;
}
inline void chmin(long long& a, long long b){
if(b < a) a = b;
}
bool vis[10];
int main(){
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
cin >> K;
for(int i = 0; i < K; i++) cin >> arr[i];
long long mn = 1e18;
for(int N = 1; N < num; N++){
memset(vis, 0, sizeof vis);
for(int i = 0; i < K; i++){
if(!check(N + i, arr[i])) vis[arr[i]] = true;
}
long long ans = 0;
for(int j = 9; j >= 0; j--){
if(vis[j]){
ans = (ans << 3) + (ans << 1);
ans += j;
}
}
if(vis[0] == 1 && ans == 0) ans = 10;
long long sum = 1;
while(sum <= N) sum = (sum << 3) + (sum << 1);
ans = ans * sum + N;
chmin(mn, ans);
}
cout << mn << '\n';
}
# | 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... |