Submission #595775

#TimeUsernameProblemLanguageResultExecution timeMemory
595775jophyyjhMartian DNA (IOI16_dna)C++14
36 / 100
14 ms432 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. Using randomized algo, we can prove that the expected num of
 * interactions <= 1.5n, which is still too much, and whether the interactor is
 * adaptive remains unknown.
 * 
 * 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: 1.5     (expected)
 * Implementation 1
*/

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


std::string analyse(int n, int T) {
    std::string current = "";
    for (;;) {
        std::vector<char> test({'0', '1'});
        std::random_shuffle(test.begin(), test.end());
        bool found = false;
        for (char c : test) {
            if (make_test(current + c)) {
                current.push_back(c);
                found = true;
                break;
            }
        }
        if (!found)     // 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...