이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 1000000007
#define LOGN 20
#define MAXN 100005
vector<pair<int,int>> req;
vector<int> DNA;
int main() {
fast
int N, K, R;
cin >> N >> K >> R;
vector<int> matching(N+1, -1);
req = vector<pair<int,int>>(R);
DNA = vector<int>(N+1);
for (int i = 1; i <= N; i++)
cin >> DNA[i];
for (int i = 0; i < R; i++) {
cin >> req[i].f >> req[i].s;
matching[req[i].f] = i;
}
int l = 1, r = 1, no_of_closed = 0;
if (matching[DNA[l]] != -1) {
req[matching[DNA[l]]].s--;
if (req[matching[DNA[l]]].s == 0)
no_of_closed++;
}
int ans = INT_MAX;
while (l <= N && r <= N) {
while (no_of_closed < R && r < N) {
r++;
if (matching[DNA[r]] != -1) {
req[matching[DNA[r]]].s--;
if (req[matching[DNA[r]]].s == 0)
no_of_closed++;
}
}
if (no_of_closed == R)
ans = min(r-l+1, ans);
if (matching[DNA[l]] != -1) {
req[matching[DNA[l]]].s++;
if (req[matching[DNA[l]]].s == 1)
no_of_closed--;
}
l++;
}
if (ans == INT_MAX)
cout << "impossible\n";
else
cout << ans << "\n";
}
# | 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... |