This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, a[N];
bool mark[N][11], sm = true;
int main() {
    ios:: sync_with_stdio(0), cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] ^ a[0]) sm = false;
    }
    for (int w = 1; w <= 1000000; w++) {
        string s = to_string(w);
        for (auto e : s)
            mark[w][e - '0'] = true;
    }
    if (sm) {
        int l = 1, r = 1;
        while (true) {
            if (r - l == n) return cout << l << '\n', 0;
            if (!mark[r][a[0]]) l = r + 1;
            r++;
        }
        return 0;
    }
    for (int w = 1; w <= 1000000; w++) {
        int cnt = w;
        bool flag = true;
        for (int i = 0; i < n; i++) {
            if (i) cnt++;
            if (!mark[cnt][a[i]]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            cout << w << '\n';
            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... |