Submission #862437

# Submission time Handle Problem Language Result Execution time Memory
862437 2023-10-18T08:37:15 Z The_Samurai Martian DNA (BOI18_dna) C++17
100 / 100
26 ms 4700 KB
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const int inf = 1e9;

int main() {
    cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n, k, m, ans = inf;
    cin >> n >> k >> m;
    vector<int> a(n), need(k), have(k);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) {
        int x, c;
        cin >> x >> c;
        need[x] = c;
    }
    int cnt = k - m;
    for (int l = 0, r = 0; r < n; r++) {
        if (have[a[r]] >= need[a[r]]) cnt--;
        have[a[r]]++;
        if (have[a[r]] >= need[a[r]]) cnt++;
        if (cnt != k) continue;
        while (cnt == k) {
            if (have[a[l]] >= need[a[l]]) cnt--;
            have[a[l]]--;
            if (have[a[l]] >= need[a[l]]) cnt++;
            l++;
        }
        ans = min(ans, r - l + 2);
    }
    if (ans == inf) cout << "impossible";
    else cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 408 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 348 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 348 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 504 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 1 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 0 ms 456 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 0 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1616 KB Output is correct
2 Correct 10 ms 1628 KB Output is correct
3 Correct 11 ms 1628 KB Output is correct
4 Correct 9 ms 1488 KB Output is correct
5 Correct 14 ms 2896 KB Output is correct
6 Correct 8 ms 1628 KB Output is correct
7 Correct 9 ms 1628 KB Output is correct
8 Correct 17 ms 3932 KB Output is correct
9 Correct 11 ms 2140 KB Output is correct
10 Correct 9 ms 1440 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 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 500 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 460 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 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 456 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 21 ms 3544 KB Output is correct
2 Correct 21 ms 3328 KB Output is correct
3 Correct 16 ms 2908 KB Output is correct
4 Correct 9 ms 1628 KB Output is correct
5 Correct 23 ms 3932 KB Output is correct
6 Correct 26 ms 4700 KB Output is correct
7 Correct 12 ms 2140 KB Output is correct
8 Correct 14 ms 2548 KB Output is correct
9 Correct 9 ms 1628 KB Output is correct
10 Correct 10 ms 1628 KB Output is correct
11 Correct 11 ms 1536 KB Output is correct
12 Correct 10 ms 1628 KB Output is correct
13 Correct 15 ms 2908 KB Output is correct
14 Correct 9 ms 1628 KB Output is correct
15 Correct 9 ms 1624 KB Output is correct
16 Correct 15 ms 3816 KB Output is correct
17 Correct 12 ms 2140 KB Output is correct
18 Correct 9 ms 1640 KB Output is correct
19 Correct 0 ms 460 KB Output is correct
20 Correct 0 ms 460 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 344 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