Submission #1013769

# Submission time Handle Problem Language Result Execution time Memory
1013769 2024-07-04T05:39:59 Z vjudge1 Martian DNA (BOI18_dna) C++17
100 / 100
27 ms 2648 KB
#include <bits/stdc++.h>
using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int n,k,q; cin >> n >> k >> q;
    int a[n], target[k] = {}, frq[k] = {};
    for (int& i : a) {
        cin >> i;
        frq[i]++;
    }

    while (q--) {
        int x, y; cin >> x >> y;
        target[x] = y;
    }
    for (int val = 0; val < k; val++) {
        if (target[val] > frq[val]) {
            cout << "impossible";
            return 0;
        } else {
            frq[val] = 0;
        }
    }

    int cnt = count(target, target + k, 0);
    int l = 0, r = -1;
    int ans = n;
    while (++r < n) {
        if (++frq[a[r]] == target[a[r]]) cnt++;
        if (cnt == k) {
            while (cnt == k) {
                if (--frq[a[l]] < target[a[l]]) {
                    cnt--;
//                    break;
                }
                l++;
            }
            ans = min(ans, r-(l-1)+1);
//            cout << l << " " << r << " " << cnt << "\n";
//            for (int x : frq) cout << x << " ";
//            cout << "\n";
//            for (int x : target) cout << x << " " ;
//            cout << "\n\n";
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 600 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 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 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1112 KB Output is correct
2 Correct 8 ms 1112 KB Output is correct
3 Correct 9 ms 1116 KB Output is correct
4 Correct 8 ms 1116 KB Output is correct
5 Correct 11 ms 1864 KB Output is correct
6 Correct 13 ms 1116 KB Output is correct
7 Correct 8 ms 1232 KB Output is correct
8 Correct 24 ms 2648 KB Output is correct
9 Correct 10 ms 1116 KB Output is correct
10 Correct 8 ms 1116 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 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 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 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 Correct 18 ms 1868 KB Output is correct
2 Correct 17 ms 1624 KB Output is correct
3 Correct 25 ms 1628 KB Output is correct
4 Correct 8 ms 1116 KB Output is correct
5 Correct 19 ms 2016 KB Output is correct
6 Correct 24 ms 2396 KB Output is correct
7 Correct 12 ms 1296 KB Output is correct
8 Correct 12 ms 1372 KB Output is correct
9 Correct 7 ms 1116 KB Output is correct
10 Correct 8 ms 1112 KB Output is correct
11 Correct 9 ms 1116 KB Output is correct
12 Correct 7 ms 1116 KB Output is correct
13 Correct 21 ms 1628 KB Output is correct
14 Correct 7 ms 1112 KB Output is correct
15 Correct 8 ms 1116 KB Output is correct
16 Correct 27 ms 2648 KB Output is correct
17 Correct 9 ms 1116 KB Output is correct
18 Correct 8 ms 1116 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 1 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 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 1 ms 348 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct