이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
const int mxN = 2e5 + 5;
int a[mxN];
int cnt[mxN];
void testCase() {
int n, k, r;
cin >> n >> k >> r;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 0; i < r; i++) {
int a, b;
cin >> a >> b;
cnt[a] = b;
}
int cc = r;
int ptr = 1;
int ans = n + 1;
for (int i = 1; i <= n; i++) {
while (ptr <= n && cc) {
cnt[a[ptr]]--;
if (cnt[a[ptr]] == 0) cc--;
ptr++;
}
if (!cc) ans = min(ans, ptr - i);
cnt[a[i]]++;
if (cnt[a[i]] == 1) cc++;
}
if (ans == n + 1) cout << "impossible\n";
else cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
testCase();
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... |