이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
const ll N = 200069;
const ll mod = 1e9 + 7;
int tc;
ll n, k, r;
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll i, j;
cin >> n >> k >> r;
ll a[n+5];
for(i = 1; i <= n; i++)
{
cin >> a[i];
}
map<ll, ll> need, cur;
for(i = 1; i <= r; i++)
{
ll x, y;
cin >> x >> y;
need[x] = y;
}
ll ans = 1e18, sz = max(0ll, k - r);
j = 1;
for(i = 1; i <= n; i++)
{
++cur[a[i]];
if(cur[a[i]] == need[a[i]])
{
++sz;
}
while(j <= n and sz == k)
{
ans = min(ans, i - j + 1);
--cur[a[j]];
if(cur[a[j]] == need[a[j]] - 1) --sz;
++j;
}
}
if(ans == 1e18)
{
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... |