이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//曇り空 のぞいた予感
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int , int> pii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 1e5 + 10;
const ll mod = 1e9+7;
#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0)
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}
int n , a[maxn];
bool cnt(int x , int d){
while(x){
if(x%10 == d)return 1;
x /= 10;
}
return 0;
}
ll f(int x){
ll ans = 1;
if(x == 0)return 10;
while(x){
ans *= 10;
x /= 10;
}
return ans;
}
ll solve(int x){
int need[10];
ms(need , 0);
int cur = x;
for(int i = 0 ; i < n ; i ++){
if(!cnt(cur , a[i])){
need[a[i]] = 1;
}
cur++;
if(cur >= 10000)return 1e18;
}
ll ans = 0;
if(need[0]){
for(int i = 1 ; i < 10 ; i ++)if(need[i]){
if(need[0])ans = i*10 , need[0] = 0;
ans = ans * 10 + i;
}
if(ans == 0)ans = 10;
ans = ans * f(x) + x;
}
else{
for(int i = 1 ; i < 10 ; i ++)if(need[i])ans = ans * 10 + i;
ans = ans * f(x) + x;
}
if(ans == 9)dokme(x);
return ans;
}
int32_t main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin >> n;
for(int i = 0 ; i < n ; i ++)
cin >> a[i];
ll ans = 1e18;
for(int i = 0 ; i < 10000 ; i ++)
ans = min(ans , solve(i));
cout << ans;
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... |