이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=2e5+10,P=998244353;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
int n,k,r;
int dna[MAX];
int cnt[MAX];
int req[MAX];
int main() {
speed;
cin>>n>>k>>r;
for (int i=1;i<=n;i++) {
cin>>dna[i];
}
memset(cnt,0,sizeof(cnt));
memset(req,0,sizeof(req));
for (int i=0;i<r;i++) {
int b,q;
cin>>b>>q;
req[b]=q;
}
int ttl=n-r;
int ans=INF;
int l=1;
for (int r=1;r<=n;r++) {
cnt[dna[r]]++;
if (cnt[dna[r]]==req[dna[r]]) ttl++;
if (ttl<n) continue;
while (cnt[dna[l]]!=req[dna[l]]) {
cnt[dna[l]]--;
l++;
}
ans=min(r-l+1,ans);
}
if (ans==INF) cout<<"impossible\n";
else cout<<ans<<"\n";
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... |