Submission #505270

# Submission time Handle Problem Language Result Execution time Memory
505270 2022-01-11T02:45:19 Z wiwiho Martian DNA (BOI18_dna) C++14
100 / 100
33 ms 4548 KB
#include <bits/stdc++.h>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, k, r;
    cin >> n >> k >> r;

    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++) cin >> a[i];

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

    int lp = 1;
    int ans = -1;
    int ok = r;
    for(int i = 1; i <= n; i++){
        cnt[a[i]]++;
        if(cnt[a[i]] == need[a[i]]) ok--;
        while(lp < i && ok == 0 && cnt[a[lp]] > need[a[lp]]){
            cnt[a[lp]]--;
            lp++;
        }
        if(ok != 0) continue;
        int len = i - lp + 1;
        if(ans == -1 || len < ans) ans = len;
    }

    if(ans == -1) cout << "impossible\n";
    else cout << ans << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1472 KB Output is correct
2 Correct 16 ms 1468 KB Output is correct
3 Correct 13 ms 1460 KB Output is correct
4 Correct 13 ms 1480 KB Output is correct
5 Correct 17 ms 2876 KB Output is correct
6 Correct 11 ms 1464 KB Output is correct
7 Correct 15 ms 1588 KB Output is correct
8 Correct 19 ms 3900 KB Output is correct
9 Correct 15 ms 1980 KB Output is correct
10 Correct 11 ms 1480 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 0 ms 308 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 3484 KB Output is correct
2 Correct 23 ms 3248 KB Output is correct
3 Correct 19 ms 2756 KB Output is correct
4 Correct 11 ms 1476 KB Output is correct
5 Correct 33 ms 4028 KB Output is correct
6 Correct 31 ms 4548 KB Output is correct
7 Correct 18 ms 2096 KB Output is correct
8 Correct 17 ms 2372 KB Output is correct
9 Correct 12 ms 1472 KB Output is correct
10 Correct 11 ms 1484 KB Output is correct
11 Correct 13 ms 1476 KB Output is correct
12 Correct 15 ms 1476 KB Output is correct
13 Correct 15 ms 2752 KB Output is correct
14 Correct 12 ms 1464 KB Output is correct
15 Correct 15 ms 1612 KB Output is correct
16 Correct 24 ms 3888 KB Output is correct
17 Correct 14 ms 2104 KB Output is correct
18 Correct 11 ms 1484 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 316 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 312 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct