Submission #666904

# Submission time Handle Problem Language Result Execution time Memory
666904 2022-11-29T21:39:32 Z divad Martian DNA (BOI18_dna) C++14
100 / 100
122 ms 4636 KB
#include <iostream>
#include <cstring>
#define MAX 200002
using namespace std;
int n,k,r,a[MAX],vf[MAX],t[MAX],x,y;

bool check(int len){
    int cnt = 0;
    memset(vf, 0, sizeof(vf));
    for(int i = 1; i <= len; i++){
        vf[a[i]]++;
        if(vf[a[i]] == t[a[i]]){
            cnt++;
        }
    }
    if(cnt == r){
        return true;
    }
    for(int i = len+1; i <= n; i++){
        if(vf[a[i]]+1 == t[a[i]]){
            cnt++;
        }
        vf[a[i]]++;
        if(vf[a[i-len]] == t[a[i-len]]){
            cnt--;
        }
        vf[a[i-len]]--;
        if(cnt == r){
            return true;
        }
    }
    return false;
}

int main()
{
    cin >> n >> k >> r;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= r; i++){
        cin >> x >> y;
        t[x] = y;
    }
    int ans = -1;
    int st = 1, dr = n;
    /// 0 0 0 1 1 1 1
    ///       ^
    while(st <= dr){
        int mid = (st+dr)/2;
        if(check(mid)){
            ans = mid;
            dr = mid-1;
        }else{
            st = mid+1;
        }
    }
    if(ans == -1){
        cout << "impossible\n";
    }else{
        cout << ans;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 1072 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 1072 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 1040 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1108 KB Output is correct
2 Correct 2 ms 1108 KB Output is correct
3 Correct 2 ms 1108 KB Output is correct
4 Correct 2 ms 1108 KB Output is correct
5 Correct 2 ms 1108 KB Output is correct
6 Correct 2 ms 1084 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 1 ms 1076 KB Output is correct
15 Correct 1 ms 1080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 2204 KB Output is correct
2 Correct 41 ms 2240 KB Output is correct
3 Correct 34 ms 2300 KB Output is correct
4 Correct 44 ms 2260 KB Output is correct
5 Correct 66 ms 3044 KB Output is correct
6 Correct 37 ms 2188 KB Output is correct
7 Correct 43 ms 2432 KB Output is correct
8 Correct 73 ms 3156 KB Output is correct
9 Correct 59 ms 2816 KB Output is correct
10 Correct 46 ms 2244 KB Output is correct
11 Correct 2 ms 1108 KB Output is correct
12 Correct 2 ms 1108 KB Output is correct
13 Correct 2 ms 1084 KB Output is correct
14 Correct 2 ms 1084 KB Output is correct
15 Correct 2 ms 1088 KB Output is correct
16 Correct 2 ms 1108 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 980 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 1 ms 980 KB Output is correct
24 Correct 1 ms 980 KB Output is correct
25 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 3924 KB Output is correct
2 Correct 94 ms 3660 KB Output is correct
3 Correct 85 ms 3392 KB Output is correct
4 Correct 26 ms 2212 KB Output is correct
5 Correct 105 ms 4412 KB Output is correct
6 Correct 122 ms 4636 KB Output is correct
7 Correct 63 ms 2892 KB Output is correct
8 Correct 75 ms 3076 KB Output is correct
9 Correct 42 ms 2172 KB Output is correct
10 Correct 43 ms 2256 KB Output is correct
11 Correct 33 ms 2244 KB Output is correct
12 Correct 40 ms 2268 KB Output is correct
13 Correct 66 ms 3044 KB Output is correct
14 Correct 37 ms 2260 KB Output is correct
15 Correct 43 ms 2304 KB Output is correct
16 Correct 74 ms 3076 KB Output is correct
17 Correct 61 ms 2800 KB Output is correct
18 Correct 45 ms 2244 KB Output is correct
19 Correct 2 ms 1108 KB Output is correct
20 Correct 2 ms 1084 KB Output is correct
21 Correct 2 ms 1080 KB Output is correct
22 Correct 2 ms 1108 KB Output is correct
23 Correct 2 ms 1108 KB Output is correct
24 Correct 2 ms 1084 KB Output is correct
25 Correct 1 ms 980 KB Output is correct
26 Correct 1 ms 980 KB Output is correct
27 Correct 1 ms 980 KB Output is correct
28 Correct 1 ms 980 KB Output is correct
29 Correct 1 ms 980 KB Output is correct
30 Correct 1 ms 1108 KB Output is correct
31 Correct 1 ms 980 KB Output is correct
32 Correct 1 ms 980 KB Output is correct
33 Correct 1 ms 980 KB Output is correct