Submission #768313

#TimeUsernameProblemLanguageResultExecution timeMemory
768313Yell0 Martian DNA (BOI18_dna)C++17
100 / 100
68 ms9236 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&&needs.size()) { cout<<"impossible\n"; return 0; } int ans=r-l; for(;l<=N;++l) { --f[d[l]]; while(f[d[l]]<req[d[l]]) { if(r>N) { cout<<ans<<'\n'; return 0; } ++f[d[r]]; ++r; } 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...