제출 #396732

#제출 시각아이디문제언어결과실행 시간메모리
396732danielcm585 Martian DNA (BOI18_dna)C++14
0 / 100
41 ms3276 KiB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second

typedef long long ll;
typedef pair<int,int> ii;

const int INF = 1e9;
int n, k, r;
vector<int> a, need, cnt;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k >> r;
    a = vector<int>(n+2);
    need = cnt = vector<int>(k,0);
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= r; i++) {
        int b, q; cin >> b >> q;
        need[b] = q;
    }
    int ans = INF, get = 0;
    for (int i = 1, j = 1; j <= n; i++) {
        while (j <= n && get < r) {
            cnt[a[j]]++;
            get += (need[a[j]] && cnt[a[j]] == need[a[j]]);
            j++;
        }
        // cout << i << " -> " << j << '\n';
        if (get == r) ans = min(ans,j-i);
        get -= (need[a[i]] && cnt[a[i]] == need[a[i]]);
        cnt[a[i]]--;
    }
    if (ans == INF) cout << "impossible\n";
    else cout << ans << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...