제출 #1123105

#제출 시각아이디문제언어결과실행 시간메모리
1123105ezzzay Martian DNA (BOI18_dna)C++20
100 / 100
82 ms2376 KiB
#include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back const int N=3e5+5; int cnt[N]; int a[N]; int req[N]; int p; void add(int x){ cnt[a[x]]++; if(cnt[a[x]]==req[a[x]])p++; } void rem(int x){ cnt[a[x]]--; if(cnt[a[x]]==req[a[x]]-1)p--; } signed main(){ int n,m,k; cin>>n>>m>>k; for(int i=1;i<=n;i++)cin>>a[i]; p=m-k; for(int i=1;i<=k;i++){ int x; cin>>x; cin>>req[x]; } int l=1,r=0; int ans=1e9; while(r<=n){ if(p==m){ ans=min(ans,r-l+1); rem(l++); } else{ add(++r); } } if(ans==1e9){ cout<<"impossible"; return 0; } 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...