이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using ll = long long;
int const nmax = 200000;
int v[1 + nmax], mn[1 + nmax], fr[1 + nmax];
int main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
int n, k, r;
std::cin >> n >> k >> r;
for(int i = 1;i <= n; i++)
std::cin >> v[i];
for(int i = 1;i <= r; i++) {
int x, y;
std::cin >> x >> y;
mn[x] = y;
}
int j = 1, cnt = 0;
while(j <= n && cnt != r) {
fr[v[j]]++;
if(fr[v[j]] == mn[v[j]])
cnt++;
j++;
}
if(j == n + 1) {
std::cout << "impossible";
return 0;
}
int ans = j - 1;
for(int i = 2;i <= n; i++) {
fr[v[i - 1]]--;
if(fr[v[i - 1]] < mn[v[i - 1]])
cnt--;
while(j <= n && cnt != r) {
fr[v[j]]++;
if(fr[v[j]] == mn[v[j]])
cnt++;
j++;
}
if(j == n + 1)
break;
ans = std::min(ans, j - i);
}
std::cout << ans;
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... |