Submission #391590

# Submission time Handle Problem Language Result Execution time Memory
391590 2021-04-19T12:14:02 Z Victor Martian DNA (BOI18_dna) C++17
100 / 100
69 ms 4676 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define per(i, a, b) for (int i = b - 1; i >= a; --i)
#define trax(a, x) for (auto& a : x)
#define sz(a) a.size()
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

int main() {
    cin.tie(0)->sync_with_stdio(0);

    int n, k, r, quant[200001], dna[200001];
    memset(quant, 0, sizeof(quant));
    cin >> n >> k >> r;
    rep(i, 0, n) cin >> dna[i];
    rep(i, 0, r) {
        int b, q;
        cin >> b >> q;
        quant[b] = q;
    }

    int lo = 1, hi = n+1;
    vi curr,dummy(n,0);

    while (lo < hi) {
        int mid = (hi + lo) >> 1,have=0;
        curr=dummy;
        bool work=0;

        rep(i, 0, mid - 1){
            int base=dna[i];
            if(++curr[base]==quant[base])++have;
        }

        rep(i,mid-1,n){
            int base=dna[i];
            ++curr[base];
            if(curr[base]==quant[base])++have;

            if(have==r){
                work=1;
                break;
            }

            base=dna[i-mid+1];
            if(quant[base]==curr[base])--have;
            --curr[base];
        }

        if(work)hi=mid;
        else lo=mid+1;
    }

    if(n<lo)cout<<"impossible"<<endl;
    else cout<<lo<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1112 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 2 ms 1120 KB Output is correct
4 Correct 2 ms 1100 KB Output is correct
5 Correct 2 ms 1100 KB Output is correct
6 Correct 2 ms 1100 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 1 ms 1100 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 3532 KB Output is correct
2 Correct 35 ms 3680 KB Output is correct
3 Correct 27 ms 3484 KB Output is correct
4 Correct 30 ms 3540 KB Output is correct
5 Correct 37 ms 3532 KB Output is correct
6 Correct 29 ms 3532 KB Output is correct
7 Correct 29 ms 4028 KB Output is correct
8 Correct 47 ms 4604 KB Output is correct
9 Correct 38 ms 4292 KB Output is correct
10 Correct 37 ms 3856 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1120 KB Output is correct
13 Correct 2 ms 1100 KB Output is correct
14 Correct 2 ms 1116 KB Output is correct
15 Correct 2 ms 1100 KB Output is correct
16 Correct 2 ms 1100 KB Output is correct
17 Correct 1 ms 1100 KB Output is correct
18 Correct 1 ms 1100 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 1 ms 1100 KB Output is correct
21 Correct 1 ms 1100 KB Output is correct
22 Correct 1 ms 1100 KB Output is correct
23 Correct 1 ms 1100 KB Output is correct
24 Correct 1 ms 1100 KB Output is correct
25 Correct 1 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 3528 KB Output is correct
2 Correct 49 ms 3568 KB Output is correct
3 Correct 55 ms 3504 KB Output is correct
4 Correct 16 ms 3500 KB Output is correct
5 Correct 50 ms 3524 KB Output is correct
6 Correct 69 ms 3524 KB Output is correct
7 Correct 38 ms 3584 KB Output is correct
8 Correct 49 ms 3568 KB Output is correct
9 Correct 37 ms 3532 KB Output is correct
10 Correct 33 ms 3484 KB Output is correct
11 Correct 26 ms 3540 KB Output is correct
12 Correct 31 ms 3592 KB Output is correct
13 Correct 38 ms 3584 KB Output is correct
14 Correct 29 ms 3536 KB Output is correct
15 Correct 29 ms 3960 KB Output is correct
16 Correct 47 ms 4676 KB Output is correct
17 Correct 35 ms 4404 KB Output is correct
18 Correct 35 ms 3728 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 2 ms 1100 KB Output is correct
21 Correct 2 ms 1100 KB Output is correct
22 Correct 2 ms 1100 KB Output is correct
23 Correct 2 ms 1116 KB Output is correct
24 Correct 2 ms 1116 KB Output is correct
25 Correct 1 ms 1100 KB Output is correct
26 Correct 1 ms 1100 KB Output is correct
27 Correct 1 ms 1100 KB Output is correct
28 Correct 1 ms 1100 KB Output is correct
29 Correct 1 ms 1100 KB Output is correct
30 Correct 1 ms 1100 KB Output is correct
31 Correct 1 ms 1100 KB Output is correct
32 Correct 1 ms 1100 KB Output is correct
33 Correct 1 ms 1100 KB Output is correct