답안 #1091316

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1091316 2024-09-20T13:21:54 Z MateiKing80 Martian DNA (BOI18_dna) C++14
100 / 100
119 ms 18468 KB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k, r;
    cin >> n >> k >> r;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];

    int q[k] = {};

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

    set<pair<int, int>> st;
    for (int i = 0; i < k; i++)
    {
        if (q[i])
            st.insert({-1, i});
    }
    vector<vector<int>> p(k);

    auto get = [&](int d)
    {
        return ((int)p[d].size() < q[d] ? -1 : p[d][(int)p[d].size() - q[d]]);
    };

    int res = n + 1;

    for (int i = 0; i < n; i++)
    {
        if (q[a[i]])
        {
            assert(st.count({get(a[i]), a[i]}));
            st.erase({get(a[i]), a[i]});
        }
        p[a[i]].push_back(i);
        if (q[a[i]])
        {
            st.insert({get(a[i]), a[i]});
        }
        if (st.begin()->first != -1)
            res = min(res, i - st.begin()->first + 1);
    }
    if (res == n + 1)
    {
        cout << "impossible\n";
        return 0;
    }
    cout << res << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 472 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 2816 KB Output is correct
2 Correct 14 ms 2840 KB Output is correct
3 Correct 18 ms 2620 KB Output is correct
4 Correct 19 ms 2924 KB Output is correct
5 Correct 20 ms 7140 KB Output is correct
6 Correct 20 ms 2652 KB Output is correct
7 Correct 13 ms 2780 KB Output is correct
8 Correct 28 ms 14168 KB Output is correct
9 Correct 16 ms 3672 KB Output is correct
10 Correct 21 ms 2620 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 488 KB Output is correct
14 Correct 1 ms 676 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 11296 KB Output is correct
2 Correct 71 ms 9216 KB Output is correct
3 Correct 37 ms 7124 KB Output is correct
4 Correct 22 ms 2788 KB Output is correct
5 Correct 119 ms 12884 KB Output is correct
6 Correct 113 ms 18468 KB Output is correct
7 Correct 88 ms 4248 KB Output is correct
8 Correct 98 ms 5200 KB Output is correct
9 Correct 16 ms 2904 KB Output is correct
10 Correct 13 ms 2836 KB Output is correct
11 Correct 18 ms 2652 KB Output is correct
12 Correct 17 ms 2876 KB Output is correct
13 Correct 20 ms 7004 KB Output is correct
14 Correct 26 ms 2700 KB Output is correct
15 Correct 12 ms 2652 KB Output is correct
16 Correct 26 ms 14024 KB Output is correct
17 Correct 16 ms 3676 KB Output is correct
18 Correct 25 ms 2904 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 452 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct