Submission #689828

#TimeUsernameProblemLanguageResultExecution timeMemory
689828Darren0724 Martian DNA (BOI18_dna)C++17
100 / 100
38 ms6740 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define all(x) x.begin(),x.end() int INF=1e18; int mod=998244353; signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n;cin>>n; int k;cin>>k; int q;cin>>q; vector<int> v(n); for(int i=0;i<n;i++){ cin>>v[i]; } vector<int> need(k); for(int i=0;i<q;i++){ int a,b;cin>>a>>b; need[a]=max(need[a],b); } int ans=INF; int l=0,r=0; vector<int> cnt(k); int sat=0; for(int i=0;i<k;i++){ if(need[i]==0){ sat++; } } function<void(void)> add=[&](){ cnt[v[r]]++; if(cnt[v[r]]==need[v[r]]){ sat++; } r++; }; function<void(void)> del=[&](){ cnt[v[l]]--; if(cnt[v[l]]==need[v[l]]-1){ sat--; } l++; }; while(1){ if(r==n){ cout<<"impossible"<<endl; return 0; } add(); if(sat==k){ break; } } ans=r-l; for(int i=1;i<n;i++){ del(); while(sat<k&&r<n){ add(); } if(sat==k){ ans=min(ans,r-l); } } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...