Submission #935678

#TimeUsernameProblemLanguageResultExecution timeMemory
935678Warinchai Martian DNA (BOI18_dna)C++14
100 / 100
38 ms4912 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...