Submission #788614

# Submission time Handle Problem Language Result Execution time Memory
788614 2023-07-20T12:15:45 Z WLZ Martian DNA (BOI18_dna) C++17
100 / 100
32 ms 4552 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
const int INF = 1e9;
const int MAXN = 2e5 + 5;
const ll LINF = 1e18;
const double pi = acos(-1);
const double EPS = 1e-9;
template <class T> using MinPQ = priority_queue<T, vector<T>, greater<T>>;
template <class T> using MaxPQ = priority_queue<T>;

int n, k, r;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n >> k >> r;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> q(k);
    int numOfMatched = k - r;
    for (int i = 0; i < r; i++) {
        int b;
        cin >> b;
        cin >> q[b];
    }
    int j = 0;
    vector<int> matched(k, 0);
    int ans = 1e9;
    int curLen = 0;
    for (int i = 0; i < n; i++) {
        matched[a[i]]++; ++curLen;
        if (matched[a[i]] == q[a[i]]) ++numOfMatched;
        if (numOfMatched == k) ans = min(ans, curLen);
        while (j <= i && numOfMatched == k) {
            matched[a[j]]--;
            if (matched[a[j]] < q[a[j]]) numOfMatched--;
            j++;
            curLen--;
            if (numOfMatched == k) ans = min(ans, curLen);
        }
    }
    if (ans > n) cout << "impossible\n";
    else cout << ans << "\n";
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 324 KB Output is correct
5 Correct 0 ms 212 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 316 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1492 KB Output is correct
2 Correct 10 ms 1492 KB Output is correct
3 Correct 10 ms 1492 KB Output is correct
4 Correct 10 ms 1492 KB Output is correct
5 Correct 14 ms 2772 KB Output is correct
6 Correct 8 ms 1492 KB Output is correct
7 Correct 9 ms 1620 KB Output is correct
8 Correct 20 ms 3912 KB Output is correct
9 Correct 12 ms 2072 KB Output is correct
10 Correct 9 ms 1492 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 3412 KB Output is correct
2 Correct 19 ms 3136 KB Output is correct
3 Correct 16 ms 2764 KB Output is correct
4 Correct 9 ms 1492 KB Output is correct
5 Correct 23 ms 4048 KB Output is correct
6 Correct 32 ms 4552 KB Output is correct
7 Correct 12 ms 2132 KB Output is correct
8 Correct 15 ms 2380 KB Output is correct
9 Correct 9 ms 1488 KB Output is correct
10 Correct 10 ms 1492 KB Output is correct
11 Correct 10 ms 1492 KB Output is correct
12 Correct 9 ms 1480 KB Output is correct
13 Correct 13 ms 2888 KB Output is correct
14 Correct 12 ms 1496 KB Output is correct
15 Correct 9 ms 1620 KB Output is correct
16 Correct 15 ms 3920 KB Output is correct
17 Correct 12 ms 2128 KB Output is correct
18 Correct 9 ms 1492 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 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 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct