Submission #1298567

#TimeUsernameProblemLanguageResultExecution timeMemory
1298567hungdt Martian DNA (BOI18_dna)C++20
100 / 100
22 ms2628 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int dem[maxn], req[maxn], a[maxn]; int n, k, r; int l, h; int remain; int ans = 1e9; int main() { ios_base :: sync_with_stdio(false); 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 x, y; cin >> x >> y; req[x] = y; remain++; } l = 1, h = 0; while (l <= n && h <= n){ while (remain > 0 && h < n){ h++; dem[a[h]]++; if (dem[a[h]] == req[a[h]]) remain--; } if (remain > 0) break; while (remain == 0 && l <= h){ dem[a[l]]--; if (dem[a[l]] < req[a[l]]) remain++; l++; } ans = min(ans, h - l + 2); } if (ans == 1e9) cout << "impossible"; else 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...