Submission #526940

#TimeUsernameProblemLanguageResultExecution timeMemory
526940lcs147Combo (IOI18_combo)C++17
97 / 100
32 ms544 KiB
#include"combo.h"
#include<bits/stdc++.h>
using namespace std;

string guess_sequence(int n) {
    srand(time(0));

    string ch  = "ABXY";
    
    int id = ch.size()-1;
    for(int i=0; i<ch.size()-1; i++) {
        int sz = press(string(1, ch[i]));
        if(sz > 0) {
            id = i;
            break;
        }
    }
    string res;
    res += ch[id];

    ch.erase(id, 1);
    auto allch = ch;

    while(res.size() < n) {
        if(res.size()*4 + 7 <= 4*n) {

            int sz = press(res + ch[0] + res + ch[1]+ch[0] + res + ch[1]+ch[1] + res + ch[1]+ch[2]);

            int id = -1;
            if(sz == res.size()+1) id = 0;
            else if(sz == res.size()+2) id = 1;
            else id = 2;

            res += ch[id];
        } else {
            int id = ch.size()-1;
            int add = 1;
            for(int i=0; i<ch.size()-1; i++) {
                int sz = press(res + string(n, ch[i]));
                if(sz > res.size()) {
                    add = sz - res.size();
                    id = i;
                    break;
                }
            }
            res += string(add, ch[id]);

            if(res.size() == add) {
                allch.erase(id, 1);
            }
            
            ch = allch;
            if(id != ch.size()-1) {
                ch.erase(id, 1);
            }
        }
    }
    return res;
}

Compilation message (stderr)

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:11:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i=0; i<ch.size()-1; i++) {
      |                  ~^~~~~~~~~~~~
combo.cpp:24:22: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |     while(res.size() < n) {
      |           ~~~~~~~~~~~^~~
combo.cpp:25:29: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |         if(res.size()*4 + 7 <= 4*n) {
      |            ~~~~~~~~~~~~~~~~~^~~~~~
combo.cpp:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |             if(sz == res.size()+1) id = 0;
      |                ~~~^~~~~~~~~~~~~~~
combo.cpp:31:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |             else if(sz == res.size()+2) id = 1;
      |                     ~~~^~~~~~~~~~~~~~~
combo.cpp:38:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |             for(int i=0; i<ch.size()-1; i++) {
      |                          ~^~~~~~~~~~~~
combo.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |                 if(sz > res.size()) {
      |                    ~~~^~~~~~~~~~~~
combo.cpp:48:27: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   48 |             if(res.size() == add) {
      |                ~~~~~~~~~~~^~~~~~
combo.cpp:53:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             if(id != ch.size()-1) {
      |                ~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...