이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cstring>
#define MAX 200002
using namespace std;
int n,k,r,a[MAX],vf[MAX],t[MAX],x,y;
bool check(int len){
int cnt = 0;
memset(vf, 0, sizeof(vf));
for(int i = 1; i <= len; i++){
vf[a[i]]++;
if(vf[a[i]] == t[a[i]]){
cnt++;
}
}
if(cnt == r){
return true;
}
for(int i = len+1; i <= n; i++){
if(vf[a[i]]+1 == t[a[i]]){
cnt++;
}
vf[a[i]]++;
if(vf[a[i-len]] == t[a[i-len]]){
cnt--;
}
vf[a[i-len]]--;
if(cnt == r){
return true;
}
}
return false;
}
int main()
{
cin >> n >> k >> r;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= r; i++){
cin >> x >> y;
t[x] = y;
}
int ans = -1;
int st = 1, dr = n;
/// 0 0 0 1 1 1 1
/// ^
while(st <= dr){
int mid = (st+dr)/2;
if(check(mid)){
ans = mid;
dr = mid-1;
}else{
st = mid+1;
}
}
if(ans == -1){
cout << "impossible\n";
}else{
cout << ans;
}
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... |