Submission #860939

# Submission time Handle Problem Language Result Execution time Memory
860939 2023-10-14T20:49:51 Z GordonRemzi007 Martian DNA (BOI18_dna) C++17
68 / 100
386 ms 1048576 KB
#include <iostream>
#include <vector>
#include <map>
#include <climits>
#define int long long

using namespace std;

signed main() {
    int n, k, r, res, le, ri, mid, ans;
    bool ok;
    map<int,int> c;
    cin >> n >> k >> r;
    vector<int> a(n);
    vector<pair<int,int>> b(r);
    vector<vector<int>> prefix(n, vector<int>(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;
    }
    if(c[a[0]]) prefix[0][c[a[0]]-1]++;
    for(int i = 1; i < n; i++) {
        for(int j = 0; j < r; j++) prefix[i][j] = prefix[i-1][j];
        if(c[a[i]]) prefix[i][c[a[i]]-1]++;
    }
    for(int z = 0; z < r; z++) {
        if(prefix[n-1][z] < b[z].second) {
            cout << "impossible\n";
            return 0;
        }
    }
    res = n;
    for(int i = 0; i < n; i++) {
        le = i, ri = n-1, ans = LLONG_MAX;
        while(le<=ri) {
            mid = (le+ri)/2;
            ok = true;
            for(int j = 0; j < r; j++) {
                if(prefix[mid][j]-(i == 0 ? 0 : prefix[i-1][j]) < b[j].second) {
                    ok = false;
                    break;
                }
            }
            if(ok) {
                ri = mid-1;
                ans = mid;
            }
            else le = mid+1;
        }
        res = min(res, ans-i+1);
    }
    cout << res << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 504 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 440 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 22108 KB Output is correct
2 Correct 42 ms 12888 KB Output is correct
3 Correct 75 ms 25432 KB Output is correct
4 Correct 68 ms 25688 KB Output is correct
5 Correct 125 ms 31624 KB Output is correct
6 Correct 48 ms 25688 KB Output is correct
7 Correct 48 ms 25940 KB Output is correct
8 Correct 166 ms 39504 KB Output is correct
9 Correct 97 ms 26756 KB Output is correct
10 Correct 66 ms 25692 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 3 ms 1116 KB Output is correct
14 Correct 3 ms 1212 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 2 ms 1112 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 386 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -