Submission #1091503

# Submission time Handle Problem Language Result Execution time Memory
1091503 2024-09-21T03:41:56 Z rjvkr2021 Martian DNA (IOI16_dna) C++17
36 / 100
1000 ms 1072 KB
#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

dna.cpp: In function 'bool is_substring(std::string&, std::string&)':
dna.cpp:28:18: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         if(pi[i] == pat.size()){
dna.cpp: In lambda function:
dna.cpp:38:25: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   38 |         if(query.size() > n){
      |            ~~~~~~~~~~~~~^~~
grader.cpp: In function 'bool make_test(std::string)':
grader.cpp:14:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for (int i = 0; i < p.size(); i++) {
      |                  ~~^~~~~~~~~~
grader.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for (int i = 1; i <= ss.size(); i++) {
      |                  ~~^~~~~~~~~~~~
grader.cpp:28:13: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   if (pr[i] == p.size()) {
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 432 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 428 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 4 ms 348 KB Output is correct
18 Correct 4 ms 348 KB Output is correct
19 Correct 4 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 4 ms 468 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 440 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 4 ms 348 KB Output is correct
26 Correct 4 ms 456 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 4 ms 348 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 4 ms 344 KB Output is correct
33 Correct 4 ms 464 KB Output is correct
34 Correct 4 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 440 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 432 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 3 ms 348 KB Output is correct
18 Correct 4 ms 348 KB Output is correct
19 Correct 4 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 4 ms 348 KB Output is correct
22 Execution timed out 1093 ms 1072 KB Time limit exceeded
23 Execution timed out 1063 ms 776 KB Time limit exceeded
24 Execution timed out 1025 ms 848 KB Time limit exceeded
25 Execution timed out 1049 ms 656 KB Time limit exceeded
26 Execution timed out 1045 ms 780 KB Time limit exceeded
27 Execution timed out 1031 ms 848 KB Time limit exceeded
28 Execution timed out 1063 ms 1072 KB Time limit exceeded
29 Execution timed out 1051 ms 848 KB Time limit exceeded
30 Execution timed out 1060 ms 492 KB Time limit exceeded
31 Execution timed out 1052 ms 1032 KB Time limit exceeded
32 Execution timed out 1018 ms 848 KB Time limit exceeded
33 Execution timed out 1098 ms 852 KB Time limit exceeded
34 Execution timed out 1020 ms 848 KB Time limit exceeded
35 Execution timed out 1049 ms 1012 KB Time limit exceeded
36 Execution timed out 1058 ms 852 KB Time limit exceeded
37 Execution timed out 1082 ms 876 KB Time limit exceeded
38 Execution timed out 1020 ms 848 KB Time limit exceeded
39 Execution timed out 1059 ms 764 KB Time limit exceeded