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 <iostream>
#include <vector>
#include <unordered_map>
#include <limits>
using namespace std;
int main() {
int N, K, R;
cin >> N >> K >> R;
vector<int> DNA(N);
for (int i = 0; i < N; ++i) {
cin >> DNA[i];
}
unordered_map<int, int> required;
for (int i = 0; i < R; ++i) {
int B, Q;
cin >> B >> Q;
required[B] = Q;
}
int left = 0, right = 0;
int satisfied = 0;
vector<int> count(K, 0);
int min_length = numeric_limits<int>::max();
while (right < N) {
if (required.find(DNA[right]) != required.end()) {
if (count[DNA[right]] < required[DNA[right]]) {
++count[DNA[right]];
if (count[DNA[right]] == required[DNA[right]]) {
++satisfied;
}
}
}
while (satisfied == R) {
int current_length = right - left + 1;
if (current_length < min_length) {
min_length = current_length;
}
if (required.find(DNA[left]) != required.end()) {
--count[DNA[left]];
if (count[DNA[left]] < required[DNA[left]]) {
--satisfied;
}
}
++left;
}
++right;
}
if (min_length == numeric_limits<int>::max()) {
cout << "impossible" << endl;
} else {
cout << min_length << endl;
}
return 0;
}
# | 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... |