Submission #267236

# Submission time Handle Problem Language Result Execution time Memory
267236 2020-08-16T02:00:05 Z PeppaPig Martian DNA (BOI18_dna) C++14
100 / 100
57 ms 4600 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

int n, k, r;
int A[N], mn[N], cnt[N], valid;

int main() {
    scanf("%d %d %d", &n, &k, &r);
    for(int i = 1; i <= n; i++) scanf("%d", A + i);
    for(int i = 1, a, b; i <= r; i++) {
        scanf("%d %d", &a, &b);
        mn[a] = b;
    }

    int ans = 1e9;
    for(int i = 1, j = 0; i <= n; i++) {
        ++cnt[A[i]];
        if(mn[A[i]] && cnt[A[i]] == mn[A[i]])
            ++valid;
        while(j + 1 < i) {
            if(cnt[A[j + 1]] - 1 < mn[A[j + 1]])
                break;
            --cnt[A[++j]];
        }
        if(valid == r) ans = min(ans, i - j);
    }
    if(ans == 1e9) printf("impossible\n");
    else printf("%d\n", ans);

    return 0;
}

Compilation message

dna.cpp: In function 'int main()':
dna.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 |     scanf("%d %d %d", &n, &k, &r);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
dna.cpp:12:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |     for(int i = 1; i <= n; i++) scanf("%d", A + i);
      |                                 ~~~~~^~~~~~~~~~~~~
dna.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 416 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1536 KB Output is correct
2 Correct 21 ms 1568 KB Output is correct
3 Correct 23 ms 1528 KB Output is correct
4 Correct 21 ms 1536 KB Output is correct
5 Correct 30 ms 2552 KB Output is correct
6 Correct 22 ms 1536 KB Output is correct
7 Correct 23 ms 1664 KB Output is correct
8 Correct 33 ms 3192 KB Output is correct
9 Correct 27 ms 2080 KB Output is correct
10 Correct 21 ms 1536 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 3448 KB Output is correct
2 Correct 41 ms 3192 KB Output is correct
3 Correct 34 ms 2936 KB Output is correct
4 Correct 20 ms 1536 KB Output is correct
5 Correct 51 ms 4088 KB Output is correct
6 Correct 57 ms 4600 KB Output is correct
7 Correct 28 ms 2168 KB Output is correct
8 Correct 33 ms 2428 KB Output is correct
9 Correct 21 ms 1536 KB Output is correct
10 Correct 22 ms 1528 KB Output is correct
11 Correct 23 ms 1536 KB Output is correct
12 Correct 21 ms 1536 KB Output is correct
13 Correct 30 ms 2560 KB Output is correct
14 Correct 21 ms 1528 KB Output is correct
15 Correct 22 ms 1664 KB Output is correct
16 Correct 35 ms 3192 KB Output is correct
17 Correct 27 ms 2176 KB Output is correct
18 Correct 21 ms 1536 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct