Submission #595769

#TimeUsernameProblemLanguageResultExecution timeMemory
595769jophyyjhMartian DNA (IOI16_dna)C++14
36 / 100
13 ms456 KiB
/**
 * OK, so we have a binary str of len n. Each time we're allowed to give a str and
 * whether the str is a substr of the original binary str is returned. The task is
 * to determine the entire str under a certain num of interactions.
 * 
 * Well it looks to me that the num of steps shall be O(n). Well, i think i've got
 * a solution by extending the current str on either side. 2n steps is now the
 * maximum.
 * 
 * We want to further lower the num of interactions. Can we directly determine the
 * first char? Well i guess the goal is to find the suffix (or equivalently the
 * prefix). In the algo above, we extend our str on the right side until it can 
 * no longer be extended; after this, we can just extend it on the left side,
 * without fearing that a "true" response corresponds to a substr which is not a
 * suffix (shifted pos). In other words, we wish to find a substr such that:
 *          make_test((substr)0), make_test((substr)1) are all false.
 * 
 * Number of steps: 2n
 * Implementation 1
*/

#include <bits/stdc++.h>
#include "dna.h"


std::string analyse(int n, int T) {
    std::string current = "";
    for (;;) {
        bool one = make_test(current + "1");
        if (one) {
            current.push_back('1');
            continue;
        }
        bool zero = make_test(current + "0");
        if (zero) {
            current.push_back('0');
            continue;
        }
        // can't append any char (at the back)
        break;
    }
    assert(int(current.size()) <= n);
    while (int(current.size()) < n) {
        if (make_test("0" + current))
            current.insert(0, 1, '0');
        else
            current.insert(0, 1, '1');
    }
    return current;
}

Compilation message (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...