제출 #828321

#제출 시각아이디문제언어결과실행 시간메모리
828321vjudge1 Martian DNA (BOI18_dna)C++17
40 / 100
2070 ms13264 KiB
#include<bits/stdc++.h>
#define se second
#define fi first
using namespace std;
const int nmax = 200002;
int N,K,R;
int arr[nmax];
map<int,int> tar;
int simp[4004];
pair<int,int> terms[nmax];
int countt[101][101][101]={0};
int hit[101]={0};
int main() {
    cin >> N >> K >> R;
    for(int i=1; i<=N; i++) {
        cin >> arr[i];
        hit[arr[i]]++;
    }
    bool impo=false;
    for(int i=1; i<=R; i++) {
        cin >> terms[i].fi >> terms[i].se;
        tar[terms[i].fi] = terms[i].se;
        if(hit[terms[i].fi]<terms[i].se) impo=true;
    }
    if(impo) {
        cout << "impossible" << endl;
        return 0;
    }
    int sem;
    int res=INT_MAX;
    for(int i=1; i<=N; i++) {
        sem = 0;
        memset(simp, 0, sizeof(simp));
        for(int j=i; j<=N; j++) {
            simp[arr[j]]++;
            if(tar.count(arr[j])>0) {
                if(simp[arr[j]]==tar[arr[j]]) {
                    sem++;
                }
            } 
            if(sem == R) {
                res = min(res, (j-i+1));
            }
        }
    }
    cout << res << endl;
    /*for(int i=1; i<=N; i++) {
        for(int j=i; j<=N; j++) {
            for(int k=i; k<=j; k++) {
                countt[i][j][arr[k]]++;
            }
        }
    }
    int shrtpath = INT_MAX;
    int k;
    int bisa;
    for(int i=1; i<=N; i++) {
        for(int j=i; j<=N; j++) {
            bisa=true;
            k=1;
            while(k<=R) {
                if(countt[i][j][terms[k].fi] < terms[k].se) {
                    bisa=false;
                    break;
                }
                k++;
            }
            if(bisa) {
                shrtpath = min(shrtpath, (j-i+1));
            }
        }
    }
    cout << shrtpath << endl;
    */
    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...