제출 #1345569

#제출 시각아이디문제언어결과실행 시간메모리
1345569BlockOG Martian DNA (BOI18_dna)C++20
100 / 100
15 ms2440 KiB
#include <bits/stdc++.h>
#include <climits>

// mrrrowwww meeowwwww :3
// go play vivid/stasis! !! !!! https://vividstasis.gay

#define fo(i, a, b) for (auto i = (a); i < (b); i++)
#define of(i, a, b) for (auto i = (b); i-- > (a);)
#define f first
#define s second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define be(a) a.begin(), a.end()
using namespace std;

int ____init = []{
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    return 0;
}();

int arr[200000];
int curr[200000];
int want[200000];
int can;

int main() {
    int n, k, r; cin >> n >> k >> r; can = k;
    fo(i, 0, n) cin >> arr[i];
    fo(i, 0, r) {
        int j, v; cin >> j >> v;
        want[j] = v;
        can--;
    }

    int res = INT_MAX;
    for (int i = 0, j = 0; i < n; i++) {
        curr[arr[i]]++;
        if (curr[arr[i]] == want[arr[i]]) can++;
        while (curr[arr[j]] > want[arr[j]]) curr[arr[j++]]--;
        if (can >= k) res = min(res, i - j + 1);
    }

    if (res < INT_MAX) cout << res;
    else cout << "impossible";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...