Submission #451952

# Submission time Handle Problem Language Result Execution time Memory
451952 2021-08-03T13:58:25 Z Sarah_Mokhtar Martian DNA (BOI18_dna) C++14
0 / 100
138 ms 25232 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define read freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define LESSGO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll N=3e6+10,M=505,OO=1e16,mod=1e9+7;
int n,k,q,req[N],a[N];
bool ok(int x){
    int cnt[N]={0},vis[N]={0};
    int valid=0;
    for(int i=0;i<x;++i){
        if(!req[a[i]]) continue;
        cnt[a[i]]++;
        if(cnt[a[i]]>=req[a[i]]&&!vis[a[i]]){
            vis[a[i]]=1;
            ++valid;
        } 
    }
    if(valid==q) return 1;
    for(int i=0,j=x;j<n;++i,++j){
        cnt[a[i]]--;
        cnt[a[j]]++;
        if(req[a[i]]&&cnt[a[i]]<req[a[i]]){
            vis[a[i]]=0;
            --valid;
        }
        if(req[a[j]]&&cnt[a[j]]>=req[a[j]]&&!vis[a[j]]){
            ++valid;
            vis[a[j]]=1;
        }
        if(valid==q) return 1; 
    }
    return 0;
    
}
int bs(){
    int low=0,high=n,med;
    while(low<high){
        med=(low+high)>>1;
        if(ok(med)) high=med;
        else low=med+1;
    }
    return low;
}
int main(){
    LESSGO;
    cin>>n>>k>>q;
    for(int i=0;i<n;++i) cin>>a[i];
    for(int i=0;i<q;++i){
        int x,y; cin>>x>>y;
        req[x]=y;
    }
    int len=bs();
    if(ok(len)) cout<<len<<'\n';
    else cout<<"impossible\n";

}
# Verdict Execution time Memory Grader output
1 Correct 30 ms 23800 KB Output is correct
2 Correct 34 ms 23756 KB Output is correct
3 Correct 30 ms 23760 KB Output is correct
4 Correct 31 ms 23716 KB Output is correct
5 Correct 31 ms 23696 KB Output is correct
6 Correct 28 ms 23808 KB Output is correct
7 Correct 33 ms 23756 KB Output is correct
8 Correct 34 ms 23804 KB Output is correct
9 Incorrect 30 ms 23708 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 23756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 92 ms 24576 KB Output is correct
2 Incorrect 102 ms 24588 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 116 ms 24888 KB Output is correct
2 Correct 121 ms 24812 KB Output is correct
3 Correct 114 ms 24812 KB Output is correct
4 Correct 83 ms 24508 KB Output is correct
5 Correct 132 ms 24900 KB Output is correct
6 Incorrect 138 ms 25232 KB Output isn't correct
7 Halted 0 ms 0 KB -