This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* 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 = -1;
for (int step = n / 2 + 1; step >= 1; step /= 2) {
while (len + step < 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 (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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |