Submission #1031147

#TimeUsernameProblemLanguageResultExecution timeMemory
1031147vjudge1 Martian DNA (BOI18_dna)C++17
100 / 100
22 ms4680 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pii pair<int, int> #define pll pair<ll, ll> #define pld pair<ld, ld> #define pb push_back #define fi first #define se second #define debug(x) cout << #x << " => " << x << endl #define all(x) x.begin(),x.end() int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,k,R;cin>>n>>k>>R; int a[n]; for(int i=0;i<n;i++) cin>>a[i]; int need[k],cnt[k]; memset(need,0,sizeof(need)); memset(cnt,0,sizeof(cnt)); for(int i=0;i<R;i++) { int b,q;cin>>b>>q; need[b]=q; } int l=0,r=0,cntOK=0,ans=1e9; while(r<n) { cnt[a[r]]++; if(cnt[a[r]]==need[a[r]]) cntOK++; r++; while(cntOK==R) { ans=min(ans,r-l); cnt[a[l]]--; if(cnt[a[l]]==need[a[l]]-1) cntOK--; l++; } } if(ans==1e9) cout<<"impossible"; else cout<<ans; 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...