Submission #951602

#TimeUsernameProblemLanguageResultExecution timeMemory
951602SaMuEl0516 Martian DNA (BOI18_dna)C++17
100 / 100
25 ms4856 KiB
#include<bits/stdc++.h> using namespace std; int q[(int)2e5+5],cnt[(int)2e5+5],a[(int)2e5+5]; int main(){ cin.tie(0)->sync_with_stdio(0); int n,k,r,x,y,ans=1e9; cin>>n>>k>>r; for(int i=0;i<n;i++)cin>>a[i]; for(int i=0;i<r;i++){ cin>>x>>y; q[x]=y; } for(int i=0,j=0;;j++){ if(j==n)break; if(++cnt[a[j]]==q[a[j]])r--; if(r==0){ while(cnt[a[i]]-1>=q[a[i]]){ cnt[a[i]]--; i++; } ans=min(ans,j-i+1); } } if(ans==1e9)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...