# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
675954 | guagua0407 | Martian DNA (BOI18_dna) | C++17 | 249 ms | 13440 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
燒雞
燒雞
燒雞 好想進選訓
燒雞
燒雞
*/
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
const int mxn=2e5+5;
int num[mxn];
map<int,int> mp;
vector<int> cntr(mxn,0);
vector<bool> isenough(mxn,false);
set<int> have;
int n;
int main() {_
//setIO("wayne");
int k,R;
cin>>n>>k>>R;
for(int i=1;i<=n;i++){
cin>>num[i];
}
for(int i=0;i<R;i++){
int x,cnt;
cin>>x>>cnt;
mp[x]=cnt;
have.insert(x);
}
int ans=n+1;
int r=0;
int cur=0;
for(int l=1;l<=n;l++){
while(cur<R and r+1<=n){
r++;
if(have.count(num[r])){
cntr[num[r]]++;
if(cntr[num[r]]>=mp[num[r]]){
if(isenough[num[r]]==false){
cur++;
}
isenough[num[r]]=true;
}
}
if(r==n) break;
}
if(cur>=R){
ans=min(ans,r-l+1);
}
if(have.count(num[l])==0) continue;
cntr[num[l]]--;
if(cntr[num[l]]<mp[num[l]]){
if(isenough[num[l]]==true){
cur--;
}
isenough[num[l]]=false;
}
}
if(ans==n+1){
cout<<"impossible";
}
else{
cout<<ans;
}
return 0;
}
//maybe its multiset not set
Compilation message (stderr)
# | 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... |