Submission #860945

# Submission time Handle Problem Language Result Execution time Memory
860945 2023-10-14T21:17:38 Z GordonRemzi007 Martian DNA (BOI18_dna) C++17
0 / 100
132 ms 14924 KB
#include <iostream>
#include <vector>
#include <map>
#include <climits>
#define int long long

using namespace std;

signed main() {
    int n, k, r, res, ri = -1;
    bool ok;
    map<int,int> c;
    cin >> n >> k >> r;
    vector<int> a(n), sum(r);
    vector<pair<int,int>> b(r);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < r; i++) {
        cin >> b[i].first >> b[i].second;
        c[b[i].first] = i+1;
    }
    //find start
    while(true) {
        if(ri == n-1) {
            cout << "impossible\n";
            return 0;
        }
        ri++;
        sum[c[a[ri]]-1]++;
        ok = true;
        for(int i = 0; i < r; i++) {
            if(sum[i] < b[i].second) {
                ok = false;
                break;
            }
        }
        if(ok) break;
    }
    //start
    res = ri+1;
    for(int i = 0; i < n; i++) {
        sum[c[a[i]]-1]--;
        ok = true;
        while(sum[c[a[i]]-1] < b[c[a[i]]-1].second) {
            if(ri == n-1) {
                ok = false;
                break;
            }
            ri++;
            sum[c[a[ri]]-1]++;
        }
        if(!ok) break;
        res = min(res, ri-i+1);
    }
    cout << res << "\n";
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 27 ms 3552 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 132 ms 14924 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -