Submission #935678

# Submission time Handle Problem Language Result Execution time Memory
935678 2024-02-29T11:12:38 Z Warinchai Martian DNA (BOI18_dna) C++14
100 / 100
38 ms 4912 KB
#include<bits/stdc++.h>
using namespace std;
int ar[200005];
int mn[200005];
int temp[200005];
int n,k,r;
bool check(int m){
    int cnt=0;
    for(int i=0;i<k;i++)temp[i]=0;
    for(int i=0;i<k;i++)if(mn[i]==0)cnt++;
    for(int i=1;i<=m;i++){
        temp[ar[i]]++;
        if(temp[ar[i]]==mn[ar[i]])cnt++;
    }
    if(cnt==k)return true;
    //cerr<<m<<" "<<cnt<<"\n";
    for(int i=m+1;i<=n;i++){
        temp[ar[i]]++;
        if(temp[ar[i]]==mn[ar[i]])cnt++;
        temp[ar[i-m]]--;
        if(temp[ar[i-m]]==mn[ar[i-m]]-1)cnt--;
        if(cnt==k)return true;
    }
    return false;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k>>r;
    for(int i=1;i<=n;i++)cin>>ar[i];
    for(int i=0;i<r;i++){
        int b;cin>>b;
        cin>>mn[b];
    }
    int st=1,en=n,ans=-1;
    while(st<=en){
        int m=(st+en)/2;
        if(check(m)){
            en=m-1;
            ans=m;
        }else{
            st=m+1;
        }
    }
    if(ans==-1)cout<<"impossible";
    else cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2536 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2904 KB Output is correct
2 Correct 19 ms 2908 KB Output is correct
3 Correct 10 ms 2908 KB Output is correct
4 Correct 12 ms 2908 KB Output is correct
5 Correct 19 ms 3716 KB Output is correct
6 Correct 12 ms 2908 KB Output is correct
7 Correct 13 ms 3164 KB Output is correct
8 Correct 24 ms 3908 KB Output is correct
9 Correct 20 ms 3420 KB Output is correct
10 Correct 17 ms 2884 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2408 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2400 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 4448 KB Output is correct
2 Correct 27 ms 4384 KB Output is correct
3 Correct 30 ms 4288 KB Output is correct
4 Correct 9 ms 2908 KB Output is correct
5 Correct 28 ms 4912 KB Output is correct
6 Correct 38 ms 4776 KB Output is correct
7 Correct 17 ms 3420 KB Output is correct
8 Correct 25 ms 3676 KB Output is correct
9 Correct 12 ms 2904 KB Output is correct
10 Correct 18 ms 2908 KB Output is correct
11 Correct 10 ms 3160 KB Output is correct
12 Correct 12 ms 2908 KB Output is correct
13 Correct 20 ms 3928 KB Output is correct
14 Correct 12 ms 2908 KB Output is correct
15 Correct 13 ms 3164 KB Output is correct
16 Correct 27 ms 3936 KB Output is correct
17 Correct 14 ms 3416 KB Output is correct
18 Correct 13 ms 2908 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct