Submission #1013798

#TimeUsernameProblemLanguageResultExecution timeMemory
1013798vjudge1 Martian DNA (BOI18_dna)C++17
100 / 100
60 ms4968 KiB
#include "bits/stdc++.h" #define F first #define S second #define ll long long #define pii pair<ll, ll> const ll mxN = 5e5 + 5; ll mod = 1e9 + 7; using namespace std; int fr[mxN]; int req[mxN]; int a[mxN]; int main(){ int n, k, rq; cin >>n>>k>>rq; for(int i = 1;i <= n;i++) cin >>a[i]; for(int i = 1;i <= rq;i++){ int x; cin >>x; cin >>req[x]; } int ans = 1e9; int l = 1, r = 1; int tc = 0; while(l <= r && r <= n){ fr[a[r]]++; if(fr[a[r]] == req[a[r]]) tc++; if(tc == rq) ans = min(ans, r - l + 1); while(tc == rq && l <= r){ ans = min(ans, r - l + 1); fr[a[l]]--; if(fr[a[l]] == req[a[l]] - 1) tc--; l++; } r++; } if(ans != 1e9) cout<<ans; else cout<<"impossible"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...