이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie()
#define ll long long
#define ull unsigned long long
#define pb push_back
#define endl "\n"
#define int ll
#define F first
#define S second
// ||
// ||
// ||
#define db double
// #define ld long double
#define short unsigned short
using namespace std;
const int inf = 1e9,MOD=1e9+7,N=3e5+5,MN=1e9+7;
void solve() {
int n,k,R;
cin>>n>>k>>R;
vector<int>v(n);
for(int i=0;i<n;i++){
cin>>v[i];
}
map<int,int>mp;
int have=0;
for(int i=0;i<R;i++){
int b,q;
cin>>b>>q;
mp[b]=q;
}
map<int,int>cur;
int l=0,r=0;
int mn=inf;
for(;r<n;r++){
cur[v[r]]++;
if(cur[v[r]]==mp[v[r]]){
have++;
}
while(have==R&&l<=r){
mn=min(mn,r-l+1);
if(cur[v[l]]==mp[v[l]]){
have--;
}
cur[v[l]]--;
l++;
}
}
if(mn==inf){
cout<<"impossible"<<endl;
}
else{
cout<<mn<<endl;
}
}
signed main() {
IOS;
// srand(time(NULL));
//freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int UwU=1;
// cin>>UwU;
for(int i=1;i<=UwU;i++) {
// cout<<"Case "<<i<<": "<<endl;
solve();
// cout<<endl;
}
}
| # | 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... |