Submission #891135

#TimeUsernameProblemLanguageResultExecution timeMemory
891135Kiameimon_Welt_Rene Martian DNA (BOI18_dna)C++14
0 / 100
499 ms16564 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int,int> #define elif else if #define dbg(v)\ cout << "line(" << __LINE__ << ") -> " << #v << " = " << (v) << endl; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k, R; cin >> n >> k >> R; int req[n], cnt[n], arr[n], sz = 0; unordered_set<int> nums; fill(req, req+n, 0); fill(cnt, cnt+n, 0); for(int i = 0; i < n; i++) cin >> arr[i]; for(int i = 0; i < R; i++){ int b, q; cin >> b >> q; sz += q; req[b] = q; nums.insert(b); } int l = 0, r = 0, ans = LLONG_MAX; while(r < n){ while(!nums.empty() && r < n){ int val = arr[r]; cnt[val]++; if(req[val] != 0 && cnt[val] >= req[val]) nums.erase(val); r++; } if(r == n) break; dbg(l); dbg(r); ans = min(ans, r-l); int val = arr[l]; cnt[val]--; dbg(cnt[val]); if(cnt[val] < req[val]) nums.insert(val); l++; } while(l <= n-sz && nums.empty()){ ans = min(ans, r-l); int val = arr[l]; cnt[val]--; if(cnt[val] < req[val]) break; l++; } if(ans == LLONG_MAX){cout << "impossible"; return 0;} 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...