답안 #382499

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
382499 2021-03-27T13:00:02 Z vishesh312 Martian DNA (BOI18_dna) C++17
100 / 100
45 ms 3948 KB
#include "bits/stdc++.h"
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
*/

#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()

using ll = long long;
const int mod = 1e9+7;

void solve(int tc) {
    int n, k, r;
    cin >> n >> k >> r;
    vector<int> v(n);
    for (auto &x : v) cin >> x;
    int nreq = n-r;
    vector<int> a(n);
    while (r--) {
        int b, q;
        cin >> b >> q;
        a[b] = q;
    }
    int ans = 1e9;
    int l = 0;
    r = 0;
    vector<int> used(n);
    while (r < n) {
        ++used[v[r]];
        if (used[v[r]] == a[v[r]]) {
            ++nreq;
        }
        while (used[v[l]] > a[v[l]]) {
            used[v[l]]--;
            ++l;
        }
        if (nreq == n) ans = min(ans, r-l+1);
        ++r;
    }
    if (ans == 1e9) cout << "impossible\n";
    else cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int tc = 1;
    //cin >> tc;
    for (int i = 1; i <= tc; ++i) solve(i);
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 2688 KB Output is correct
2 Correct 17 ms 2668 KB Output is correct
3 Correct 19 ms 2796 KB Output is correct
4 Correct 16 ms 2668 KB Output is correct
5 Correct 21 ms 2668 KB Output is correct
6 Correct 15 ms 2668 KB Output is correct
7 Correct 16 ms 2668 KB Output is correct
8 Correct 24 ms 3948 KB Output is correct
9 Correct 21 ms 3692 KB Output is correct
10 Correct 17 ms 3052 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 2668 KB Output is correct
2 Correct 30 ms 2668 KB Output is correct
3 Correct 25 ms 2668 KB Output is correct
4 Correct 17 ms 2668 KB Output is correct
5 Correct 45 ms 2668 KB Output is correct
6 Correct 43 ms 2668 KB Output is correct
7 Correct 20 ms 2668 KB Output is correct
8 Correct 23 ms 2796 KB Output is correct
9 Correct 16 ms 2668 KB Output is correct
10 Correct 17 ms 2668 KB Output is correct
11 Correct 17 ms 2796 KB Output is correct
12 Correct 17 ms 2668 KB Output is correct
13 Correct 20 ms 2668 KB Output is correct
14 Correct 16 ms 2668 KB Output is correct
15 Correct 16 ms 2712 KB Output is correct
16 Correct 24 ms 3948 KB Output is correct
17 Correct 20 ms 3692 KB Output is correct
18 Correct 18 ms 3052 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 364 KB Output is correct