# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
330266 | nandonathaniel | Martian DNA (BOI18_dna) | C++14 | 134 ms | 12672 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>
using namespace std;
int mini[200005],byk[200005];
int s[200005];
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n,k,r,x,y;
cin >> n >> k >> r;
for(int i=0;i<n;i++)cin >> s[i];
for(int i=1;i<=r;i++){
cin >> x >> y;
mini[x]=y;
}
set<int> valid;
for(int i=0;i<k;i++){
if(mini[i]==0)valid.insert(i);
}
int ans=n+1,awal=0,akhir=0;
byk[s[0]]++;
if(byk[s[0]]==mini[s[0]])valid.insert(s[0]);
while(awal<=akhir && akhir<n){
bool stat=(valid.size()==k);
if(!stat){
if(akhir<n-1){
akhir++;
byk[s[akhir]]++;
if(byk[s[akhir]]==mini[s[akhir]])valid.insert(s[akhir]);
}
else break;
}
else{
ans=min(ans,akhir-awal+1);
byk[s[awal]]--;
if(byk[s[awal]]==mini[s[awal]]-1)valid.erase(s[awal]);
awal++;
}
}
if(ans==n+1)cout << "impossible\n";
else cout << ans << '\n';
return 0;
}
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... |