제출 #396735

#제출 시각아이디문제언어결과실행 시간메모리
396735danielcm585 Martian DNA (BOI18_dna)C++14
40 / 100
2077 ms10444 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second typedef long long ll; typedef pair<int,int> ii; const int N = 2e5; int n, k, r; int a[N+2]; map<int,int> need, cnt; bool can(int mid) { cnt.clear(); int get = 0; for (int i = 1; i <= n; i++) { cnt[a[i]]++; if (need.count(a[i]) && cnt[a[i]] == need[a[i]]) get++; if (i-mid >= 1) { if (need.count(a[i-mid]) && cnt[a[i-mid]] == need[a[i-mid]]) get--; cnt[a[i-mid]]--; } if (i >= mid && get == r) return 1; } return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k >> r; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= r; i++) { int b, q; cin >> b >> q; need[b] = q; } int ans = -1; for (int l = 1, r = n; l <= r; ) { int mid = (l+r)/2; // cout << mid << " -> " << can(mid) << '\n'; if (can(mid)) { ans = mid; r = mid-1; } else l = mid+1; } if (ans == -1) cout << "impossible\n"; else cout << ans << '\n'; 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...