제출 #865569

#제출 시각아이디문제언어결과실행 시간메모리
865569azimanov수열 (BOI14_sequence)C++17
9 / 100
507 ms4444 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

bool getbit(int mask, int bit) {
    return mask & (1 << bit);
}

const int N = 1e6 + 10;
const int K = 1e5 + 10;
int b[K];
int mask[N];

void init() {
    mask[0] = (1 << 0);
    for (int i = 1; i <= N - 1; i++) {
        for (int j = i; j >= 1; j /= 10) {
            mask[i] |= (1 << (j % 10));
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    init();

    int k;
    cin >> k;
    for (int i = 1; i <= k; i++) {
        cin >> b[i];
    }
    if (k >= 1000 + 1) {
        cout << "1\n";
        return 0;
    }
    int ans = -1;
    for (int n = 1; n + k - 1 <= N - 1; n++) {
        bool ok = true;
        for (int i = 1; i <= k; i++) {
            ok &= getbit(mask[n + i - 1], b[i]);
        }
        if (ok) {
            ans = n;
            break;
        }
    }
    cout << ans << "\n";

#ifdef LOCAL
    cout << "\nTime elapsed: " << double(clock()) / CLOCKS_PER_SEC << " s.\n";
#endif
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...