# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
932575 | imarn | Martian DNA (BOI18_dna) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
#define vp vector<pii>
using namespace std;
const int N=2e5+5;
unordered_map<ll,int>mp,up;
ll a[N];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,k,R;cin>>n>>k>>R;
for(int i=0;i<n;i++)cin>>a[i],mp[a[i]]=0;
for(int i=0;i<R;i++){
ll b,q;cin>>b>>q;up[b]=q;
}int cnt=0;int l=0,ans=1e9;
for(int i=0;i<n;i++){mp[a[i]]++;if(up.find(a[i])!=up.end()&&mp[a[i]]==up[a[i]])cnt++;
while(up.find(a[l])==up.end()||(cnt==R&&mp[a[l]]>up[a[l]]))mp[a[l]]--,l++;
}if(cnt==R)ans=min(ans,i-l+1);
if(ans==1e9)cout<<"impossible";
else cout<<ans;
}