Submission #657637

#TimeUsernameProblemLanguageResultExecution timeMemory
657637MilosMilutinovic Martian DNA (BOI18_dna)C++14
100 / 100
34 ms4540 KiB
/** * author: wxhtzdy * created: 10.11.2022 15:50:40 **/ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k, r; cin >> n >> k >> r; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> need(k, -1); for (int i = 0; i < n; i++) { int b, q; cin >> b >> q; need[b] = q; } int cnt_good = 0; vector<int> cnt(k); int ptr = -1; int ans = n + 1; auto Add = [&](int x) { cnt[x] += 1; if (cnt[x] == need[x]) { cnt_good += 1; } }; auto Remove = [&](int x) { if (cnt[x] == need[x]) { cnt_good -= 1; } cnt[x] -= 1; }; for (int i = 0; i < n; i++) { while (ptr + 1 < n && cnt_good < r) { ptr += 1; Add(a[ptr]); } if (cnt_good == r) { ans = min(ans, ptr - i + 1); } Remove(a[i]); } if (ans > n) { 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...