답안 #597621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
597621 2022-07-16T12:14:26 Z jophyyjh Martian DNA (IOI16_dna) C++14
100 / 100
12 ms 384 KB
/**
 * 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.
 * Hmm, this doesn't seem to work. My second solution is quite interesting. We
 * begin by testing 0, if 0 isn't there we add 1 to our current str. Each time, we
 * test a char and add it if it's a true, otherwise we add the other char. So, we
 * know that now only a prefix of our str is actually in the original str, so
 * there's where we can use binary search.
 * ------------------------------ After Some Hints ------------------------------
 * We try to improve the process of finding a suffix. The "search to the RHS +
 * binary search" method works, but we need to be careful about WHEN to start our
 * binary search. We don't have to ask 0/1 randomly, but can instead default to
 * asking 1. Hmm, when we've exceeded the RHS, we naturally get a series of
 * "false", meaning that we would think that a series of 0000...0 is added. Now
 * comes the ingenious part. We first use binary search to find the longest
 * contigous chain with all 0s (suppose the len is k). Therefore, we use at most
 * k+1 more steps ((k+1) consecutive "false"s), but then we determined the k 0s in
 * log(n) steps. So we have: (n-k)+log(n)+(k+1)+log(n) ~ n + 2log(n).
 * 
 * Number of steps: n + 2log(n)
 * Implementation 2
*/

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


std::string analyse(int n, int T) {
    int longest_0 = 0;
    for (int step = n / 2 + 1; step >= 1; step /= 2) {
        while (longest_0 + step <= n && make_test(std::string(longest_0 + step, '0')))
            longest_0 += step;
    }
    std::string current(longest_0, '0');
    for (int consec_zero = 0; consec_zero <= longest_0; ) {
        if (make_test(current + '1'))
            current += '1', consec_zero = 0;
        else
            current += '0', consec_zero++;
    }
    int len = 0;
    for (int step = n / 2 + 1; step >= 1; step /= 2) {
        while (len + step <= std::min(int(current.size()), n)
                && make_test(current.substr(0, len + step))) {
            len += step;
        }
    }
    current = current.substr(0, len);
    while (int(current.length()) < n) {
        if (make_test('1' + current))
            current.insert(0, 1, '1');
        else
            current.insert(0, 1, '0');
    }
    return current;
}

Compilation message

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()) {
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 0 ms 300 KB Output is correct
10 Correct 0 ms 300 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 296 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 300 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 304 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 300 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 296 KB Output is correct
22 Correct 9 ms 384 KB Output is correct
23 Correct 9 ms 384 KB Output is correct
24 Correct 8 ms 384 KB Output is correct
25 Correct 11 ms 360 KB Output is correct
26 Correct 11 ms 360 KB Output is correct
27 Correct 5 ms 340 KB Output is correct
28 Correct 6 ms 340 KB Output is correct
29 Correct 12 ms 328 KB Output is correct
30 Correct 5 ms 332 KB Output is correct
31 Correct 5 ms 380 KB Output is correct
32 Correct 12 ms 336 KB Output is correct
33 Correct 8 ms 340 KB Output is correct
34 Correct 8 ms 340 KB Output is correct
35 Correct 6 ms 356 KB Output is correct
36 Correct 7 ms 340 KB Output is correct
37 Correct 6 ms 376 KB Output is correct
38 Correct 9 ms 340 KB Output is correct
39 Correct 8 ms 364 KB Output is correct