제출 #1366856

#제출 시각아이디문제언어결과실행 시간메모리
1366856maya_s Martian DNA (BOI18_dna)C++20
100 / 100
15 ms3396 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll n, k, r; cin >> n >> k >> r;
    vector<ll> v(n), cnt(k);
    for(ll i = 0; i < n; i++) cin >> v[i];
    for(ll i = 0; i < r; i++){
        ll a, c; cin >> a >> c;
        cnt[a] = -c;
    }
    ll b = 0, tot = 0, ans = inf; 
    for(ll a = 0; a < n; a++){
        if(a) {
            cnt[v[a-1]]--;
            if(cnt[v[a-1]] < 0) tot--;
        }
        while(tot < r && b < n) {
            cnt[v[b]]++;
            if(cnt[v[b]] == 0) tot++;
            b++;
        } 
        if(tot == r) ans = min(ans, (b - a));
    }
    if(ans == inf) cout << "impossible";
    else cout << ans;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…