제출 #464980

#제출 시각아이디문제언어결과실행 시간메모리
464980marko콤보 (IOI18_combo)C++17
0 / 100
33 ms344 KiB
#include <bits/stdc++.h>

using namespace std;

// string s= "XB";

// int guesses{};

int press(string p);
// {
//     guesses++;
//     int ans{};

//     for (auto i=0;i<p.size();i++) {
//         for (auto j=i;(j<p.size())&&((j-i)<s.size())&&(p[j]==s[j-i]);j++) {
//             ans=max(ans, j-i+1);
//         }
//     }

//     return ans;
// }

string guess_sequence(int N) {
    // figure out the first letter

    if (N==1) {
        if (press("A")==1) return "A";
        else if (press("B")==1) return "B";
        else if (press("X")==1) return "X";
        else return "Y";
    }

    char first={};

    auto res=press("AB");
    if (res==2) {
        first='A';
    }
    else if (res==1) {
        if (press("A")==1) 
            first='A';
        else 
            first='B';
    }
    else if (press("X")) 
        first='X';
    else 
        first='Y';
        
    string ans{};

    ans+=first;
    for (int i=1;i<N-1;i++) {
        if (first=='A') {
            string ask=ans+'X'+first+ans+"YB"+ans+"YY"+ans+"YX";
            auto res=press(ask);

            //cout << "i="<<i<<",ans="<<ans<<endl;
            if (res==ans.size())
            {
                // B
                ans+='B';
            }
            else if(res==ans.size()+1)
            {
                ans+='X';
            }
            else 
            {
                ans+='Y';
            }
        }
        else if (first=='B') {
            string ask=ans+'X'+first+ans+"YA"+ans+"YY"+ans+"YX";
            auto res=press(ask);
            if (res==ans.size())
            {
                ans+='A';
            }
            else if(res==ans.size()+1)
            {
                ans+='X';
            }
            else 
            {
                ans+='Y';
            } 
        }
        else if (first=='X') {
            string ask=ans+'A'+first+ans+"YB"+ans+"YY"+ans+"YX";
            auto res=press(ask);
            if (res==ans.size())
            {
                ans+='B';
            }
            else if(res==ans.size()+1)
            {
                ans+='A';
            }
            else 
            {
                ans+='Y';
            } 
        }
        else if (first=='Y') {
            string ask=ans+'A'+first+ans+"XB"+ans+"XY"+ans+"XX";
            auto res=press(ask);
            if (res==ans.size())
            {
                ans+='B';
            }
            else if(res==ans.size()+1)
            {
                ans+='A';
            }
            else 
            {
                ans+='X';
            } 
        }
    }

    if (first=='A') {
        if (press(ans+'B')==ans.size()+1) {
            ans+='B';
        }
        else if (press(ans+'X')==ans.size()+1)
        {
            ans+='X';
        }
        else ans+='Y';

    }
    else if (first=='B') {
        if (press(ans+'A')==ans.size()+1) {
            ans+='A';
        }
        else if (press(ans+'X')==ans.size()+1)
        {
            ans+='X';
        }
        else ans+='Y';

    }
    else if (first=='X') {
        if (press(ans+'B')==ans.size()+1) {
            ans+='B';
        }
        else if (press(ans+'A')==ans.size()+1)
        {
            ans+='A';
        }
        else ans+='Y';

    }
    else if (first=='Y') {
        if (press(ans+'B')==ans.size()+1) {
            ans+='B';
        }
        else if (press(ans+'X')==ans.size()+1)
        {
            ans+='X';
        }
        else ans+='A';   
    }

    return ans;
}

// auto main() -> int {
//     cout << guess_sequence(2) << endl;
//     cout << guesses << endl;
// }

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

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:59:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |             if (res==ans.size())
      |                 ~~~^~~~~~~~~~~~
combo.cpp:64:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |             else if(res==ans.size()+1)
      |                     ~~~^~~~~~~~~~~~~~
combo.cpp:76:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |             if (res==ans.size())
      |                 ~~~^~~~~~~~~~~~
combo.cpp:80:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |             else if(res==ans.size()+1)
      |                     ~~~^~~~~~~~~~~~~~
combo.cpp:92:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |             if (res==ans.size())
      |                 ~~~^~~~~~~~~~~~
combo.cpp:96:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |             else if(res==ans.size()+1)
      |                     ~~~^~~~~~~~~~~~~~
combo.cpp:108:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |             if (res==ans.size())
      |                 ~~~^~~~~~~~~~~~
combo.cpp:112:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |             else if(res==ans.size()+1)
      |                     ~~~^~~~~~~~~~~~~~
combo.cpp:124:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  124 |         if (press(ans+'B')==ans.size()+1) {
      |             ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
combo.cpp:127:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |         else if (press(ans+'X')==ans.size()+1)
      |                  ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
combo.cpp:135:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  135 |         if (press(ans+'A')==ans.size()+1) {
      |             ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
combo.cpp:138:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  138 |         else if (press(ans+'X')==ans.size()+1)
      |                  ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
combo.cpp:146:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  146 |         if (press(ans+'B')==ans.size()+1) {
      |             ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
combo.cpp:149:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  149 |         else if (press(ans+'A')==ans.size()+1)
      |                  ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
combo.cpp:157:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  157 |         if (press(ans+'B')==ans.size()+1) {
      |             ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
combo.cpp:160:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  160 |         else if (press(ans+'X')==ans.size()+1)
      |                  ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...