이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxN = 2e5+10;
int N, K, R;
void solve() {
cin >> N >> K >> R;
vector<int> DNA(N), need(K, INT_MAX);
for (auto& dna : DNA)
cin >> dna;
for (int i = 0; i < R; i++) {
int B, Q;
cin >> B >> Q;
need[B] = Q;
}
int ans = INT_MAX;
int good = 0;
for (int l = 0, r = 0; l < N; l++) {
while(good < R && r < N)
if (--need[DNA[r++]] == 0)
++good;
if (good == R)
ans = min(ans, r - l);
if (++need[DNA[l]] == 1)
--good;
}
cout << (ans == INT_MAX ? "impossible" : to_string(ans));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
# | 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... |