답안 #1111270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1111270 2024-11-12T00:57:36 Z ShadowShark Martian DNA (BOI18_dna) C++17
100 / 100
25 ms 4680 KB
#include <bits/stdc++.h>
using namespace std;

const int maxN = 2e5 + 5;
int D[maxN], req[maxN], cnt[maxN];

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, k, q;
    cin >> n >> k >> q;

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

    for (int i = 1; i <= q; i++) {
        int x, y;
        cin >> x >> y;

        req[x] = y;
    }

    int satisfied = 0;
    for (int i = 0; i < k; i++)
        if (cnt[i] >= req[i]) satisfied++;

    int R = 0, ans = n + 1;
    for (int L = 1; L <= n; L++) {
        while (R <= n && satisfied != k) {
            R++; if (R > n) break;
            cnt[D[R]]++; if (cnt[D[R]] == req[D[R]]) satisfied++;
        }

        if (R > n) break; ans = min(ans, R - L + 1);
        if (cnt[D[L]] == req[D[L]]) satisfied--;
        cnt[D[L]]--;
    }

    if (ans == n + 1) cout << "impossible";
        else cout << ans;
    return 0;
}

Compilation message

dna.cpp: In function 'int main()':
dna.cpp:34:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   34 |         if (R > n) break; ans = min(ans, R - L + 1);
      |         ^~
dna.cpp:34:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   34 |         if (R > n) break; ans = min(ans, R - L + 1);
      |                           ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1496 KB Output is correct
2 Correct 10 ms 1640 KB Output is correct
3 Correct 10 ms 1672 KB Output is correct
4 Correct 9 ms 1548 KB Output is correct
5 Correct 13 ms 2812 KB Output is correct
6 Correct 9 ms 1616 KB Output is correct
7 Correct 9 ms 1756 KB Output is correct
8 Correct 16 ms 3152 KB Output is correct
9 Correct 13 ms 2140 KB Output is correct
10 Correct 15 ms 1628 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 500 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 3540 KB Output is correct
2 Correct 19 ms 3152 KB Output is correct
3 Correct 15 ms 2900 KB Output is correct
4 Correct 9 ms 1812 KB Output is correct
5 Correct 25 ms 4168 KB Output is correct
6 Correct 25 ms 4680 KB Output is correct
7 Correct 17 ms 2128 KB Output is correct
8 Correct 14 ms 2384 KB Output is correct
9 Correct 8 ms 1616 KB Output is correct
10 Correct 9 ms 1616 KB Output is correct
11 Correct 10 ms 1640 KB Output is correct
12 Correct 9 ms 1616 KB Output is correct
13 Correct 13 ms 2648 KB Output is correct
14 Correct 9 ms 1616 KB Output is correct
15 Correct 9 ms 1616 KB Output is correct
16 Correct 14 ms 3152 KB Output is correct
17 Correct 12 ms 2128 KB Output is correct
18 Correct 8 ms 1624 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 528 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct