답안 #1025002

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1025002 2024-07-16T14:03:22 Z phoenix Martian DNA (BOI18_dna) C++17
100 / 100
135 ms 18576 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.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 0 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 604 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 348 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 460 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 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 17 ms 2904 KB Output is correct
2 Correct 13 ms 2832 KB Output is correct
3 Correct 17 ms 2652 KB Output is correct
4 Correct 16 ms 2768 KB Output is correct
5 Correct 19 ms 7004 KB Output is correct
6 Correct 38 ms 2640 KB Output is correct
7 Correct 11 ms 2648 KB Output is correct
8 Correct 28 ms 14084 KB Output is correct
9 Correct 15 ms 3624 KB Output is correct
10 Correct 22 ms 2644 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 464 KB Output is correct
14 Correct 1 ms 604 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 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 464 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 11196 KB Output is correct
2 Correct 83 ms 9132 KB Output is correct
3 Correct 49 ms 7064 KB Output is correct
4 Correct 13 ms 2784 KB Output is correct
5 Correct 135 ms 12916 KB Output is correct
6 Correct 122 ms 18576 KB Output is correct
7 Correct 94 ms 4136 KB Output is correct
8 Correct 95 ms 5240 KB Output is correct
9 Correct 26 ms 2856 KB Output is correct
10 Correct 13 ms 2848 KB Output is correct
11 Correct 24 ms 2688 KB Output is correct
12 Correct 20 ms 2900 KB Output is correct
13 Correct 21 ms 7012 KB Output is correct
14 Correct 22 ms 2756 KB Output is correct
15 Correct 13 ms 2652 KB Output is correct
16 Correct 36 ms 14016 KB Output is correct
17 Correct 15 ms 3676 KB Output is correct
18 Correct 25 ms 2596 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 352 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 352 KB Output is correct
24 Correct 1 ms 352 KB Output is correct
25 Correct 0 ms 352 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 456 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 1 ms 600 KB Output is correct