Submission #768312

#TimeUsernameProblemLanguageResultExecution timeMemory
768312Yell0 Martian DNA (BOI18_dna)C++17
0 / 100
50 ms7132 KiB
#include <bits/stdc++.h> using namespace std; const int MN=2e5+2; int N,K,R,d[MN],req[MN],f[MN]; int main() { ios::sync_with_stdio(0);cin.tie(0); cin>>N>>K>>R; for(int i=1;i<=N;++i) cin>>d[i]; set<int> needs; for(int i=1;i<=R;++i) { int b,q; cin>>b>>q; req[b]=q; needs.insert(b); } int l=1,r=1; for(;r<=N;++r) { if(needs.empty()) break; if(++f[d[r]]==req[d[r]]) needs.erase(d[r]); } if(r>N) { cout<<"impossible\n"; return 0; } int ans=r-l; for(;l<=N;++l) { --f[d[l]]; while(f[d[l]]<req[d[l]]&&r<=N) { ++req[d[r]]; ++r; } if(r>N) { cout<<ans<<'\n'; return 0; } ans=min(ans,r-l-1); } cout<<ans<<'\n'; 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...