제출 #1031510

#제출 시각아이디문제언어결과실행 시간메모리
1031510ArthuroWich콤보 (IOI18_combo)C++17
30 / 100
29 ms1092 KiB
#include "combo.h"
#include<bits/stdc++.h>
using namespace std;
string guess_sequence(int n) {
    string s;
    int v;
    v = press("AB");
    if (v == 2) {
        s = "AB";
    } else if (v == 1) {
        v = press("A");
        if (v == 1) {
            s = "A";
        } else {
            s = "B";
        }
    } else {
        v = press("XY");
        if (v == 2) {
            s = "XY";
        } else {
            v = press("X");
            if (v == 1) {
                s = "X";
            } else {
                s = "Y";
            }
        }
    }
    if (n == 1) {
        return s;
    } else if (s.length() == n) {
        return s;
    }
    vector<string> alp;
    for (char c : "ABXY") {
        if (c != s[0]) {
            string t = "";
            t.push_back(c);
            alp.push_back(t);
        }
    }
    while(s.length() != n) {
        int si = 0, a = 1;
        while((si+1+s.length())*3*a < 4*n) {
            si++;
            a *= 3;
        }
        si = min(si, n-(int)s.length());
        vector<vector<string>> c(si);
        c[0].push_back(s+alp[0]);
        c[0].push_back(s+alp[1]);
        c[0].push_back(s+alp[2]);
        for (int i = 1; i < si; i++) {
            for (string e : c[i-1]) {
                c[i].push_back(e+alp[0]);
                c[i].push_back(e+alp[1]);
                c[i].push_back(e+alp[2]);
            }
        }
        int ch = s.length()+si;
        int l = 0, r = c[si-1].size()-1;
        while(l < r) {
            int m = (l+r)/2;
            string s1 = "";
            for (int i = m+1; i <= r; i++) {
                s1 += c[si-1][i];
            }
            if (press(s1) != ch) {
                r = m;
            } else {
                l = m+1;
            }
        }
        v = s.length();
        for (int i = v; i < c[si-1][l].length(); i++) {
            s.push_back(c[si-1][l][i]);
        }
    }
    return s;
}

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

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:32:27: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |     } else if (s.length() == n) {
      |                ~~~~~~~~~~~^~~~
combo.cpp:43:22: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |     while(s.length() != n) {
      |           ~~~~~~~~~~~^~~~
combo.cpp:45:37: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |         while((si+1+s.length())*3*a < 4*n) {
      |               ~~~~~~~~~~~~~~~~~~~~~~^~~~~
combo.cpp:76:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for (int i = v; i < c[si-1][l].length(); i++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...