# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1091503 | rjvkr2021 | Martian DNA (IOI16_dna) | C++17 | 1098 ms | 1072 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 "dna.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool is_substring(string &txt, string &pat){
string s = pat + "#" + txt;
int n = s.size();
vector<int> pi(n);
pi[0] = 0;
int l = 0, i = 1;
while(i < n){
if(s[i] == s[l]){
l++;
pi[i] = l;
i++;
}
else{
if(l == 0){
pi[i] = 0;
i++;
}
else{
l = pi[l - 1];
}
}
}
for(int i = pat.size() + 1; i < n; i++){
if(pi[i] == pat.size()){
return true;
}
}
return false;
}
string analyse(int n, int t) {
vector<string> yes, no;
string query;
auto valid_query = [&](){
if(query.size() > n){
return false;
}
for(string &t: yes){
if(!is_substring(query, t)){
return false;
}
}
for(string &t: no){
if(is_substring(query, t)){
return false;
}
}
return true;
};
bool response;
bool suffix_found = false;
while(true){
if(suffix_found){
query.insert(query.begin(), '0'); // try zero
if(valid_query()){
response = make_test(query);
if(response){
yes.pb(query);
continue;
}
else{
no.pb(query);
}
}
query[0] = '1'; // try one
if(valid_query()){
response = make_test(query);
if(response){
yes.pb(query);
continue;
}
else{
no.pb(query);
}
}
query.erase(query.begin());
return query;
}
else{
query.pb('0'); // try zero
if(valid_query()){
response = make_test(query);
if(response){
yes.pb(query);
continue;
}
else{
no.pb(query);
}
}
query.back() = '1'; // try one
if(valid_query()){
response = make_test(query);
if(response){
yes.pb(query);
continue;
}
else{
no.pb(query);
}
}
query.pop_back();
suffix_found = true;
}
}
}
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... |