Submission #576291

# Submission time Handle Problem Language Result Execution time Memory
576291 2022-06-12T23:52:34 Z mmonteiro Martian DNA (BOI18_dna) C++17
100 / 100
121 ms 4520 KB
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <iomanip>

int main(){

    int n, k, r;

    std::cin >> n >> k >> r;

    std::vector<int> nucleobase(n);
    std::vector<int> frequency(k);

    for(int i = 0; i < n; ++i) {
        std::cin >> nucleobase[i];
    }

    for(int i = 0; i < r; ++i) {
        int x, f;
        std::cin >> x >> f;
        frequency[x] += f;
    }

    auto add = [&](int x, std::vector<int> &frequency_aux, int &qtd_ok) {
        frequency_aux[x]++;
        if(frequency_aux[x] == frequency[x] and frequency[x] > 0) {
            qtd_ok++;
        }
    };

    auto sub = [&](int x, std::vector<int> &frequency_aux, int &qtd_ok) {
        if(frequency_aux[x] == frequency[x] and frequency[x] > 0) {
            qtd_ok--;
        }
        frequency_aux[x]--;
    };

    auto check = [&](int window_size) {
        std::vector<int> frequency_aux(k);
        int qtd_ok = 0;
        for(int i = 0; i < window_size; ++i) {
            add(nucleobase[i], frequency_aux, qtd_ok);
        }
        if(qtd_ok == r) {
            return true;
        }
        for(int i = window_size; i < n; ++i) {
            sub(nucleobase[i - window_size], frequency_aux, qtd_ok);
            add(nucleobase[i], frequency_aux, qtd_ok);
            if(qtd_ok == r) {
                return true;
            }
        }
        return false;
    };

    int lo = 0, hi = n, ans = -1;

    while(lo <= hi) {
        int middle = (lo + hi) / 2;
        if(check(middle)) {
            hi = middle - 1;
            ans = middle;
        } else {
            lo = middle + 1;
        }
    }

    if(ans == -1) {
        std::cout << "impossible\n";
    } else {
        std::cout << ans << '\n';
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 448 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 292 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 0 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 1472 KB Output is correct
2 Correct 49 ms 1476 KB Output is correct
3 Correct 39 ms 1452 KB Output is correct
4 Correct 43 ms 1468 KB Output is correct
5 Correct 65 ms 2836 KB Output is correct
6 Correct 38 ms 1484 KB Output is correct
7 Correct 47 ms 1580 KB Output is correct
8 Correct 74 ms 3908 KB Output is correct
9 Correct 57 ms 1996 KB Output is correct
10 Correct 44 ms 1464 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 296 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 94 ms 3556 KB Output is correct
2 Correct 91 ms 3112 KB Output is correct
3 Correct 79 ms 2844 KB Output is correct
4 Correct 29 ms 1364 KB Output is correct
5 Correct 121 ms 4136 KB Output is correct
6 Correct 120 ms 4520 KB Output is correct
7 Correct 76 ms 2116 KB Output is correct
8 Correct 77 ms 2304 KB Output is correct
9 Correct 41 ms 1468 KB Output is correct
10 Correct 50 ms 1456 KB Output is correct
11 Correct 38 ms 1492 KB Output is correct
12 Correct 44 ms 1484 KB Output is correct
13 Correct 66 ms 2832 KB Output is correct
14 Correct 41 ms 1468 KB Output is correct
15 Correct 49 ms 1652 KB Output is correct
16 Correct 76 ms 3908 KB Output is correct
17 Correct 57 ms 1996 KB Output is correct
18 Correct 43 ms 1456 KB Output is correct
19 Correct 2 ms 320 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Correct 2 ms 312 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 300 KB Output is correct
31 Correct 0 ms 304 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct