# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
891007 | AccountName | Martian DNA (BOI18_dna) | C++14 | 20 ms | 3160 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
signed main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
int dna_len, alphabet_size, req_nucleobase_no;
cin >> dna_len >> alphabet_size >> req_nucleobase_no;
int dna[dna_len];
for(int i = 0; i < dna_len; i++)
{
cin >> dna[i];
}
int req_nucleobase[alphabet_size];
int extra_nucleobases[alphabet_size];
for(int i = 0; i < alphabet_size; i++)
{
req_nucleobase[i] = -1;
extra_nucleobases[i] = 0;
}
for(int i = 0; i < req_nucleobase_no; i++)
{
int nucleobase;
cin >> nucleobase;
cin >> req_nucleobase[nucleobase];
}
int no_of_req_met, shortest_len = 0;
int left = 0;
for(int right = 0; right < dna_len; right++)
{
if(req_nucleobase[dna[right]] > 0)
{
req_nucleobase[dna[right]]--;
if(req_nucleobase[dna[right]] == 0)
{
no_of_req_met++;
}
}
else
{
extra_nucleobases[dna[right]]++;
}
while((req_nucleobase[dna[left]] == -1 or extra_nucleobases[dna[left]] > 0) and left < right)
{
//cout << left << " " << dna[left] << " ";
//cout << req_nucleobase[dna[left]] << " " << extra_nucleobases[dna[left]] << "\n";
left++;
extra_nucleobases[dna[left]]--;
}
if(no_of_req_met == req_nucleobase_no)
{
int curr_len = right - left + 1;
shortest_len = (shortest_len == 0)? curr_len : min(curr_len, shortest_len);
}
//cout << left << " test " << right << "\n";
}
if(no_of_req_met != req_nucleobase_no)
{
cout << "impossible";
}
else
{
cout << shortest_len;
}
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... |