Submission #521467

#TimeUsernameProblemLanguageResultExecution timeMemory
521467JooMartian DNA (IOI16_dna)C++17
100 / 100
13 ms380 KiB
#include "dna.h" #include <bits/stdc++.h> #include <cstdlib> using namespace std; std::string analyse(int n, int t) { if(!make_test("0")) return string(n, '1'); string str(n, '0'); int l = 1, r = n, longest_zero = -1; while(l <= r){ int mid = (l+r)>>1; if(make_test(str.substr(0, mid))){ longest_zero = mid; l = mid+1; } else { r = mid-1; } } assert(longest_zero != -1); str = str.substr(0, longest_zero); int cntz = longest_zero; while(str.size() < n){ if(make_test(str+"1")){ str += "1"; cntz = 0; } else { cntz++; if(cntz > longest_zero){ break; } str += "0"; } } l = 0, r = str.size()-longest_zero; int endpoint = -1; while(l <= r){ int mid = (l+r)>>1; if(make_test(str.substr(0, longest_zero+mid))){ endpoint = longest_zero+mid; l = mid+1; } else { r = mid-1; } } str = str.substr(0, endpoint); while(str.size() < n){ if(make_test("1"+str)){ str = "1" + str; } else { str = "0" + str; } } return str; }

Compilation message (stderr)

dna.cpp: In function 'std::string analyse(int, int)':
dna.cpp:25:22: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |     while(str.size() < n){
      |           ~~~~~~~~~~~^~~
dna.cpp:51:22: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   51 |     while(str.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...