# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
643394 | devariaota | Martian DNA (BOI18_dna) | C++17 | 2065 ms | 21132 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.
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const ll MOD=1e9+7;
using namespace std;
ll N,M,K,a[200005];
vector <ll> vec[200005];
vector <pair<ll,ll> > pr[200005];
int main(){
cin>>N>>M>>K;
for(int i=1;i<=N;i++){
cin>>a[i];
vec[a[i]].push_back(i);
}
bool ok=true;
for(int i=1;i<=K;i++){
ll x,y;
cin>>x>>y;
// cout<<vec[x].size()<<' '<<y<<endl;
if(vec[x].size()<y){
ok=false;
}
else{
for(int j=y-1;j<vec[x].size();j++){
pr[i].push_back({vec[x][j-(y-1)],vec[x][j]});
}
}
}
if(!ok){
cout<<"impossible"<<endl;
return 0;
}
ll minn=1e18;
for(int i=1;i<=N;i++){
ll maks=0;
bool ok=true;
for(int j=1;j<=K;j++){
ll l=0;
ll r=pr[j].size()-1;
ll ans=-1;
while(l<=r){
ll m=(l+r)/2;
if(pr[j][m].fi>=i){
ans=m;
r=m-1;
}
else{
l=m+1;
}
}
if(ans==-1){
ok=false;
break;
}
maks=max(maks,pr[j][ans].se);
}
if(ok){
minn=min(minn,maks-i+1);
}
}
cout<<minn<<endl;
}
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... |