# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
651084 | dooompy | Martian DNA (BOI18_dna) | C++17 | 367 ms | 15348 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;
int states[200005];
map<int, pair<int, int>> req;
set<int> completed;
map<int, int> have;
int n, k, r;
bool move(int &idx) {
if (completed.size() == r) return true;
while (completed.size() < r) {
idx++;
if (idx > n) return false;
have[states[idx]]++;
if (have[states[idx]] == req[states[idx]].first) {
completed.insert(req[states[idx]].second);
}
}
return true;
}
int main() {
cin >> n >> k >> r;
for (int i = 1; i <= n; i++) cin >> states[i];
for (int i = 0; i < r; i++) {
int b, q; cin >> b >> q;
req[b] = {q, i};
}
int idx = 0;
bool able = move(idx);
if (!able) {
cout << "impossible";
return 0;
}
int l = 1;
int ans = (idx - l + 1);
// cout << l << " " << idx << endl;
while (l < n) {
if (req[states[l]].first == have[states[idx]]) {
completed.erase(req[states[idx]].second);
}
have[states[idx]]--;
l++;
able = move(idx);
if (!able) break;
ans = min(ans, idx - l + 1);
}
cout << ans;
}
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... |