# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
421931 | MetalPower | Sequence (BOI14_sequence) | C++14 | 0 ms | 0 KiB |
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 = 1e4;
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;
}
inline void solve_sub3(){
ll size = N - 1, calc = 1, l = 0;
if(arr[0] == 0){
while(size >= calc){
size -= calc;
calc = (calc << 3) + (calc << 1);
l++;
}
cout << "10";
for(int i = 1; i <= l; i++) cout << "0";
}else if(arr[0] == 9){
while(size >= calc){
size -= calc;
calc = (calc << 3) + (calc << 1);
l++;
}
for(int i = 1; i <= l; i++) cout << "8";
cout << "9";
}else{
while(size){
size /= 10; l++;
}
cout << arr[0];
for(int i = 1; i <= l; i++) cout << "0";
}
cout << '\n';
}
bool vis[10];
int main(){
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
cin >> K;
bool eq = true;
for(int i = 0; i < K; i++){
cin >> arr[i]; if(arr[i] != arr[0]) eq = false;
}
if(eq){
solve_sub3();
}else{
long long mn = 1e18;
for(int N = 1; N < num; N++){
bool pos = true;
for(int i = 0; i < K; i++){
if(!check(N + i, arr[i])){
pos = false; break;
}
}
if(pos) chmin(mn, (long long) N);
}
cout << mn << '\n';
}
}