Submission #1267198

#TimeUsernameProblemLanguageResultExecution timeMemory
1267198canhnam357 Martian DNA (BOI18_dna)C++20
100 / 100
21 ms3400 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k, r; cin >> n >> k >> r; int ans = INT_MAX; vector<int> a(n); for (int& i : a) cin >> i; vector<int> has(k), need(k), cnt(k); for (int i = 0; i < r; i++) { int b, q; cin >> b >> q; has[b] = 1; need[b] = q; } int cur = 0; for (int i = 0, j = 0; j < n; j++) { if (has[a[j]]) { cnt[a[j]]++; if (cnt[a[j]] == need[a[j]]) cur++; } while (cur == r) { if (has[a[i]]) { cnt[a[i]]--; if (cnt[a[i]] < need[a[i]]) cur--; } i++; } if (i) ans = min(ans, j - i + 2); } if (ans == INT_MAX) cout << "impossible"; else cout << ans; cout << '\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...