# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
891139 | Hhw48 | Martian DNA (BOI18_dna) | C++14 | 2058 ms | 4336 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;
#define int long long
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,k,r;
cin>>n>>k>>r;
string s="";
int tmp=0,tmp2=0;
for(int i=0; i<n; i++){
char x;
cin>>x;
s += x;
}
multiset<int>mset;
unordered_set <int> uset;
vector<pii>vec;
for(int i=0; i<r; i++){
int a,b;
cin>>a>>b;
vec.pb({a,b});
tmp += b;
uset.insert(a);
}
for(int i=0; i<n; i++){
if(uset.count(s[i]-'0')==1){
tmp2++;
}
}
if(tmp2<tmp){
cout<<"impossible";
return 0;
}
for(int i=tmp; i<n; i++){
for(int x=0; x<=n-i; x++){
int idx=x;
while(idx<=x+i){
if(uset.count(s[idx]-'0')==1){
mset.insert(s[idx]-'0');
}
idx++;
}
bool flag=false;
for(int j=0; j<r; j++){
if(mset.count(vec[j].fi)<vec[j].se)flag=true;
}
if(flag==0){
cout<<i;
exit(0);
}
mset.clear();
}
}
}
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... |