이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = (int) 2e5 + 7;
const int INF = (int) 1e9 + 7;
int n;
int k;
int r;
int base[N];
int min_quantity[N];
int f[N];
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
///freopen ("input.txt", "r", stdin);
cin >> n >> k >> r;
for (int i = 0; i < n; i++) {
cin >> base[i];
}
for (int i = 0; i < r; i++) {
int base_id;
cin >> base_id;
cin >> min_quantity[base_id];
}
int unsolved_restrictions = r;
int l = 0, sol = INF;
for (int r = 0; r < n; r++) {
f[base[r]]++;
unsolved_restrictions -= (min_quantity[base[r]] > 0 && f[base[r]] == min_quantity[base[r]]);
if (unsolved_restrictions == 0) {
while (min_quantity[base[l]] == 0 || f[base[l]] != min_quantity[base[l]]) {
f[base[l++]]--;
}
sol = min(sol, r - l + 1);
}
}
if (sol == INF) {
cout << "impossible\n";
return 0;
}
cout << sol << "\n";
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... |