Submission #891102

#TimeUsernameProblemLanguageResultExecution timeMemory
891102Kiameimon_Welt_Rene Martian DNA (BOI18_dna)C++14
0 / 100
34 ms8300 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); } if(sz > n){cout << "impossible"; return 0;} int l = 0, r = 0, ans = LLONG_MAX; bool stop = false; while(l < n-sz){ if(l == 0 && r == n) break; while(!nums.empty()){ if(l == 0 && r == n) stop = true; int val = arr[r]; cnt[val]++; if(req[val] != 0 && cnt[val] >= req[val])nums.erase(val); if(!nums.empty()) r++; } if(stop) break; ans = min(ans, r-l+1); int val = arr[l]; cnt[val]--; if(req[val] != 0 && cnt[val] < req[val]) nums.insert(val); l++; } fill(cnt, cnt+n, 0); for(int i = n-sz+1; i < n; i++) cnt[arr[i]]++; bool ok = true; for(int i = 0; i < n; i++){ if(req[i] > cnt[i]) ok = false; } if(ok) ans = min(ans, sz); 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...