제출 #1366293

#제출 시각아이디문제언어결과실행 시간메모리
1366293hyyh Martian DNA (BOI18_dna)C++20
100 / 100
135 ms147500 KiB
#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <iomanip>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using piii = tuple<int,int,int>;
#define f first
#define s second
#define endl '\n'
#define all(x) begin(x),end(x)
#define m_p make_pair

int main(){
    int n;cin >> n;
    int k;cin >> k;
    int r;cin >> r;
    vector<int> vc;
    vector<int> need(k,0);
    vector<vector<int>> color(k);
    vector<queue<int>> next(k);
    for(int i{};i < n;i++){
        int g;cin >> g;
        vc.emplace_back(g);
        color[g].emplace_back(i);
    }
    int ans = n;
    int cur = 0;
    for(int i{};i < r;i++){
        int a,b;cin >> a >> b;
        need[a] = b;
        if(b > color[a].size()){
            cout << "impossible";
            return 0;
        }
        for(int j{};j+b-1 < color[a].size();j++){
            next[a].emplace(color[a][j+b-1]);
        }
        cur = max(cur,next[a].front());
    }
    for(int i{};i < n;i++){
        cur = max(cur,i+1);
        if(need[vc[i]]){
            next[vc[i]].pop();
            if(next[vc[i]].empty()) break;
            cur = max(cur,next[vc[i]].front());
        }
        ans = min(ans,cur-i);
    }
    cout << ans;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…