# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1111270 | ShadowShark | Martian DNA (BOI18_dna) | C++17 | 25 ms | 4680 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 5;
int D[maxN], req[maxN], cnt[maxN];
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, k, q;
cin >> n >> k >> q;
for (int i = 1; i <= n; i++)
cin >> D[i];
for (int i = 1; i <= q; i++) {
int x, y;
cin >> x >> y;
req[x] = y;
}
int satisfied = 0;
for (int i = 0; i < k; i++)
if (cnt[i] >= req[i]) satisfied++;
int R = 0, ans = n + 1;
for (int L = 1; L <= n; L++) {
while (R <= n && satisfied != k) {
R++; if (R > n) break;
cnt[D[R]]++; if (cnt[D[R]] == req[D[R]]) satisfied++;
}
if (R > n) break; ans = min(ans, R - L + 1);
if (cnt[D[L]] == req[D[L]]) satisfied--;
cnt[D[L]]--;
}
if (ans == n + 1) cout << "impossible";
else cout << ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |