Submission #653705

#TimeUsernameProblemLanguageResultExecution timeMemory
653705Juan Martian DNA (BOI18_dna)C++14
100 / 100
310 ms10504 KiB
#include<bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; #define pii pair<int, int> #define ll long long int v[maxn], need[maxn]; map<int, int> mp; int main(){ int n, k, m; cin >> n >> k >> m; for(int i = 0; i < n; i++) cin >> v[i]; for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; need[a] = b; } int l = 0, r = 0; int ans = n+1, invalid_cnt = m; while(l<n){ bool term = false; while(invalid_cnt){ if(r==n) {term = true; break;} mp[v[r]]++; if(mp[v[r]]==need[v[r]]) invalid_cnt--; r++; } if(term==true) break; while(true){ if(mp[v[l]]==need[v[l]]) break; mp[v[l]]--; l++; } ans = min(ans, r-l); mp[v[l]]--, invalid_cnt++, l++; } if(ans == n+1) cout << "impossible\n"; else cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...