Submission #526740

#TimeUsernameProblemLanguageResultExecution timeMemory
526740lcs147Combo (IOI18_combo)C++17
30 / 100
33 ms664 KiB
#include<bits/stdc++.h>
#include"combo.h"
using namespace std;

string guess_sequence(int n) {
    vector<char> possible  = {'A','B','X','Y'};
    
    char first = possible.back();
    int cnt = 1;
    for(int i=0; i<3; i++) {
        char c = possible[i];
        int sz = press(string(n, c));
        if(sz > 0) {
            cnt = sz;
            first = c;
            break;
        }
    }
    string res = string(cnt, first);

    possible.erase(find(possible.begin(), possible.end(), first));
    auto allpossible = possible;

    while(res.size() < n) {

        if(possible.size() == 2) {
            int cur = possible[1];
            int cnt = 1;

            int sz = press(res + string(n, possible[0]));
            bool is0 = false;
            if(sz > res.size()) {
                cur = possible[0];
                cnt = sz-res.size();
                is0 = true;
            }

            res += string(cnt, cur);
            possible = allpossible;
            if(is0) {
                possible.erase(find(possible.begin(), possible.end(), cur));
            }
        } else {
            int sz = press(res + string(n, possible[0]) + res + string(n, possible[1]));
            if(sz == res.size()) {
                res += possible[2];
                possible = allpossible;
            } else {
                int id = 1;
                if(press(res + string(n, possible[0])) > res.size()) {
                    id = 0;
                }
                res += string(sz-res.size(), possible[id]);
                possible = allpossible;
                possible.erase(find(possible.begin(), possible.end(), possible[id]));
            }
        }
    }
    return res;
}

Compilation message (stderr)

combo.cpp: In function 'std::string guess_sequence(int)':
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:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |             if(sz > res.size()) {
      |                ~~~^~~~~~~~~~~~
combo.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |             if(sz == res.size()) {
      |                ~~~^~~~~~~~~~~~~
combo.cpp:50:56: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |                 if(press(res + string(n, possible[0])) > res.size()) {
      |                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...