Submission #320905

# Submission time Handle Problem Language Result Execution time Memory
320905 2020-11-10T08:18:47 Z gustason Martian DNA (BOI18_dna) C++14
100 / 100
184 ms 24032 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 5;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, r, q;
    cin >> n >> r >> q;

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

    vector<int> need(r+1, INF), cnt(r+1, 0);
    for(int i = 0; i < q; i++) {
        int b;
        cin >> b;
        cin >> need[b];
    }

    int good = 0, ans = INF;
    set<int> begins, ends;
    vector<int> pos[r+1];
    for(int i = 0; i < n; i++) {
        int c = dna[i];
        cnt[c]++;
        pos[c].push_back(i);
        if (cnt[c] == need[c]) {
            good++;
            begins.insert(pos[c][0]);
            ends.insert(pos[c][need[c]-1]);
        }
        if (cnt[c] > need[c]) {
            begins.erase(pos[c][cnt[c]-need[c]-1]);
            ends.erase(pos[c][cnt[c]-2]);
            begins.insert(pos[c][cnt[c]-need[c]]);
            ends.insert(pos[c][cnt[c]-1]);
        }
        if (good == q) {
            ans = min(ans, *ends.rbegin() - *begins.begin() + 1);
        }
    }

    if (ans == INF) {
        cout << "impossible";
    } else {
        cout << ans << "\n";
    }

//    cout << good << "\n";
//    for(auto i : ends) {
//        cout << i << "\n";
//    }
    return 0;
}
//~ check for overflows
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 2916 KB Output is correct
2 Correct 25 ms 2856 KB Output is correct
3 Correct 39 ms 2540 KB Output is correct
4 Correct 31 ms 2876 KB Output is correct
5 Correct 35 ms 7396 KB Output is correct
6 Correct 16 ms 2796 KB Output is correct
7 Correct 20 ms 2668 KB Output is correct
8 Correct 69 ms 14948 KB Output is correct
9 Correct 27 ms 3684 KB Output is correct
10 Correct 44 ms 2692 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 0 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 184 ms 15460 KB Output is correct
2 Correct 148 ms 12388 KB Output is correct
3 Correct 58 ms 8292 KB Output is correct
4 Correct 29 ms 2688 KB Output is correct
5 Correct 65 ms 9700 KB Output is correct
6 Correct 158 ms 24032 KB Output is correct
7 Correct 119 ms 4452 KB Output is correct
8 Correct 156 ms 6116 KB Output is correct
9 Correct 40 ms 2916 KB Output is correct
10 Correct 25 ms 2856 KB Output is correct
11 Correct 36 ms 2532 KB Output is correct
12 Correct 31 ms 2884 KB Output is correct
13 Correct 35 ms 7404 KB Output is correct
14 Correct 17 ms 2796 KB Output is correct
15 Correct 20 ms 2668 KB Output is correct
16 Correct 69 ms 14948 KB Output is correct
17 Correct 26 ms 3704 KB Output is correct
18 Correct 42 ms 2692 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 620 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct