제출 #1298591

#제출 시각아이디문제언어결과실행 시간메모리
1298591Trn115 Martian DNA (BOI18_dna)C++20
100 / 100
25 ms4752 KiB
#include <bits/stdc++.h> #define int long long using namespace std; constexpr int N = 2e5+5; int n, k, r; int d[N]; int cnt[N], req[N]; int sated; void solve() { for (int i = 0; i < k; ++i) { sated += req[i] == 0; } int j = 1, res = n + 1; for (int i = 1; i <= n; ++i) { ++cnt[d[i]]; if (cnt[d[i]] == req[d[i]]) ++sated; while (j < i && cnt[d[j]] - 1 >= req[d[j]]) { --cnt[d[j]]; ++j; } if (sated == k) res = min(res, i - j + 1); } if (res == n + 1) cout << "impossible"; else cout << res; } signed main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> k >> r; for (int i = 1; i <= n; ++i) { cin >> d[i]; } for (int i = 1; i <= r; ++i) { int b, q; cin >> b >> q; req[b] = q; } solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...