이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 200'010;
int a[N], cnt[N];
int n, k, r;
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> n >> k >> r;
Loop (i,0,n)
cin >> a[i];
Loop (i,0,r) {
int b, q;
cin >> b >> q;
cnt[b] = q;
}
int ans = n+1;
int p = 0;
int pos = r;
Loop (i,0,n) {
while (pos) {
if (p == n)
goto end;
cnt[a[p]]--;
pos -= cnt[a[p]] == 0;
++p;
}
ans = min<int>(ans, p - i);
pos += cnt[a[i]] == 0;
cnt[a[i]]++;
}
end:
if (ans == n+1)
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... |