제출 #401703

#제출 시각아이디문제언어결과실행 시간메모리
401703dxz05콤보 (IOI18_combo)C++14
97 / 100
43 ms688 KiB
#include "combo.h"
#include <bits/stdc++.h>

using namespace std;

string abxy = "ABXY";

string guess_sequence(int n) {
    string s;
    for (int i = 0; i < 3; i++){
        string p;
        p += abxy[i];
        if (press(p) == 1){
            s = p;
            break;
        }
    }

    if (s.empty()) s = "Y";

    if (n == 1) return s;

    string abxy2 = abxy;
    abxy.clear();
    for (char ch : abxy2){
        if (s[0] != ch) abxy += ch;
    }

    while (s.size() < n - 1){
        string p;
        for (int i = 0; i < 3; i++){
            p += s + abxy[0] + abxy[i];
        }
        p += s + abxy[1];

        int x = press(p);

        char ch;
        if (x == s.size()) ch = abxy[2]; else
        if (x == s.size() + 1) ch = abxy[1]; else
            ch = abxy[0];
        s += ch;
    }

    if (press(s + abxy[0]) == n){
        s += abxy[0];
    } else if (press(s + abxy[1]) == n){
        s += abxy[1];
    } else s += abxy[2];

    return s;
}

컴파일 시 표준 에러 (stderr) 메시지

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:29:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |     while (s.size() < n - 1){
      |            ~~~~~~~~~^~~~~~~
combo.cpp:39:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         if (x == s.size()) ch = abxy[2]; else
      |             ~~^~~~~~~~~~~
combo.cpp:40:15: 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 (x == s.size() + 1) ch = abxy[1]; else
      |             ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...