Submission #329481

#TimeUsernameProblemLanguageResultExecution timeMemory
329481mihai145Martian DNA (IOI16_dna)C++14
100 / 100
15 ms492 KiB
#include "dna.h" #include <cstdlib> #include <random> int failureCt = 19; std::string analyse(int n, int t) { std::string randomSuffix = ""; int failures = 0; while(failures < failureCt && randomSuffix.size() < n) { int rnd = rand() % 2; if(rnd == 0) { bool res = make_test(randomSuffix + '0'); if(res == true) { randomSuffix += '0'; failures = 0; } else { randomSuffix += '1'; failures++; } } else { bool res = make_test(randomSuffix + '1'); if(res == true) { randomSuffix += '1'; failures = 0; } else { randomSuffix += '0'; failures++; } } } std::string root = "", rnd = ""; for(int i = 0; i < (int)randomSuffix.size(); i++) { if(i + failures >= (int)randomSuffix.size()) { rnd += randomSuffix[i]; } else { root += randomSuffix[i]; } } int st = 0, dr = (int)rnd.size(), sol = 0; while(st <= dr) { int mid = (st + dr) >> 1; std::string toQ = root; for(int i = 0; i < mid; i++) toQ += rnd[i]; bool res = make_test(toQ); if(res == true) { sol = mid; st = mid + 1; } else { dr = mid - 1; } } for(int i = 0; i < sol; i++) root += rnd[i]; while((int)root.size() < n) { bool res = make_test('0' + root); if(res == true) { root = '0' + root; } else { root = '1' + root; } } return root; }

Compilation message (stderr)

dna.cpp: In function 'std::string analyse(int, int)':
dna.cpp:13:55: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   13 |     while(failures < failureCt && randomSuffix.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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...