Submission #1093843

# Submission time Handle Problem Language Result Execution time Memory
1093843 2024-09-27T16:16:30 Z IvanGar Martian DNA (BOI18_dna) C++17
100 / 100
86 ms 12424 KB
#include <iostream>
#include <vector>
#include <unordered_map>
#include <climits>

using namespace std;

int main() {
    
    int n, a, r;
    cin >> n >> a >> r;

    vector<int> dna(n);
    for (int i = 0; i < n; ++i) {
        cin >> dna[i];
    }

    unordered_map<int, int> required;  
    for (int i = 0; i < r; ++i) {
        int nucleobase, quantity;
        cin >> nucleobase >> quantity;
        required[nucleobase] = quantity;
    }

    
    unordered_map<int, int> current_count;
    int matched = 0;  
    int min_len = INT_MAX;  
    int start = 0;

    for (int end = 0; end < n; ++end) {
        int end_base = dna[end];
        if (required.find(end_base) != required.end()) {
            current_count[end_base]++;
            if (current_count[end_base] == required[end_base]) {
                matched++;
            }
        }

        while (matched == required.size()) {
            min_len = min(min_len, end - start + 1);
            int start_base = dna[start];
            if (required.find(start_base) != required.end()) {
                current_count[start_base]--;
                if (current_count[start_base] < required[start_base]) {
                    matched--;
                }
            }
            start++;
        }
    }

    
    if (min_len == INT_MAX) {
        cout << "impossible" << endl;
    } else {
        cout << min_len << endl;
    }

    return 0;
}

Compilation message

dna.cpp: In function 'int main()':
dna.cpp:40:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::unordered_map<int, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         while (matched == required.size()) {
      |                ~~~~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 596 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 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 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 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
10 Correct 0 ms 436 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1372 KB Output is correct
2 Correct 23 ms 1596 KB Output is correct
3 Correct 24 ms 1512 KB Output is correct
4 Correct 22 ms 1628 KB Output is correct
5 Correct 37 ms 2356 KB Output is correct
6 Correct 19 ms 1600 KB Output is correct
7 Correct 23 ms 1596 KB Output is correct
8 Correct 44 ms 2360 KB Output is correct
9 Correct 31 ms 2140 KB Output is correct
10 Correct 21 ms 1372 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 436 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 9152 KB Output is correct
2 Correct 64 ms 7776 KB Output is correct
3 Correct 47 ms 3920 KB Output is correct
4 Correct 23 ms 1368 KB Output is correct
5 Correct 78 ms 9568 KB Output is correct
6 Correct 86 ms 12424 KB Output is correct
7 Correct 35 ms 2644 KB Output is correct
8 Correct 44 ms 3664 KB Output is correct
9 Correct 20 ms 1624 KB Output is correct
10 Correct 22 ms 1628 KB Output is correct
11 Correct 23 ms 1628 KB Output is correct
12 Correct 22 ms 1640 KB Output is correct
13 Correct 36 ms 2128 KB Output is correct
14 Correct 19 ms 1596 KB Output is correct
15 Correct 22 ms 1624 KB Output is correct
16 Correct 38 ms 2344 KB Output is correct
17 Correct 31 ms 2128 KB Output is correct
18 Correct 22 ms 1472 KB Output is correct
19 Correct 1 ms 440 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct