답안 #878173

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878173 2023-11-24T06:36:38 Z vjudge1 Martian DNA (BOI18_dna) C++17
100 / 100
28 ms 3920 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10;

int n, k, m;
int a[N], b[N], cnt[N], cont, ans = N;

int main() {
	ios:: sync_with_stdio(0), cin.tie(0);
    cin >> n >> k >> m;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        b[x] = y;
    }
    for (int i = 0; i < k; i++)
        if (!b[i]) cont++;
    for (int l = 0, r = 0; l < n; l++) {
        while (r < n && cont ^ k) {
            cnt[a[r++]]++;
            if (cnt[a[r - 1]] == b[a[r - 1]]) cont++;
        }
        if (cont == k) ans = min(ans, r - l);
        cnt[a[l]]--;
        if (cnt[a[l]] + 1 == b[a[l]]) cont--;
    }
    if (ans == N) cout << "impossible" << '\n';
    else cout << ans << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2512 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 2908 KB Output is correct
2 Correct 9 ms 3012 KB Output is correct
3 Correct 10 ms 2908 KB Output is correct
4 Correct 11 ms 2928 KB Output is correct
5 Correct 13 ms 3408 KB Output is correct
6 Correct 8 ms 2908 KB Output is correct
7 Correct 9 ms 3004 KB Output is correct
8 Correct 15 ms 3408 KB Output is correct
9 Correct 11 ms 3420 KB Output is correct
10 Correct 9 ms 2908 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2532 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2648 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 3668 KB Output is correct
2 Correct 21 ms 3668 KB Output is correct
3 Correct 16 ms 3744 KB Output is correct
4 Correct 9 ms 2908 KB Output is correct
5 Correct 22 ms 3832 KB Output is correct
6 Correct 28 ms 3920 KB Output is correct
7 Correct 12 ms 3392 KB Output is correct
8 Correct 15 ms 3420 KB Output is correct
9 Correct 8 ms 2904 KB Output is correct
10 Correct 9 ms 2908 KB Output is correct
11 Correct 11 ms 2940 KB Output is correct
12 Correct 9 ms 2908 KB Output is correct
13 Correct 13 ms 3496 KB Output is correct
14 Correct 9 ms 2904 KB Output is correct
15 Correct 9 ms 2908 KB Output is correct
16 Correct 14 ms 3408 KB Output is correct
17 Correct 11 ms 3420 KB Output is correct
18 Correct 9 ms 2904 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2520 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2516 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 0 ms 2516 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct