제출 #595635

#제출 시각아이디문제언어결과실행 시간메모리
595635AlperenT콤보 (IOI18_combo)C++17
100 / 100
54 ms11316 KiB
#include <bits/stdc++.h> #include "combo.h" using namespace std; char chr[3]; map<string, int> mp; int ask(string str){ if(mp.find(str) == mp.end()) mp[str] = press(str); return mp[str]; } string guess_sequence(int n){ string s; if(ask("AB")){ if(ask("A")){ s = "A"; chr[0] = 'B', chr[1] = 'X', chr[2] = 'Y'; } else{ s = "B"; chr[0] = 'A', chr[1] = 'X', chr[2] = 'Y'; } } else{ if(ask("X")){ s = "X"; chr[0] = 'A', chr[1] = 'B', chr[2] = 'Y'; } else{ s = "Y"; chr[0] = 'A', chr[1] = 'B', chr[2] = 'X'; } } while(s.size() < n){ if(n - s.size() >= 3){ string nextstr = s + chr[0] + chr[0] + chr[0] + s + chr[0] + chr[1] + chr[0] + s + chr[0] + chr[2] + chr[0] + s + chr[1] + chr[0] + chr[0]; if(ask(nextstr) - s.size() == 0) s += chr[2]; else if(ask(nextstr) - s.size() == 1){ if(ask(s + chr[1] + chr[1]) - s.size() >= 2) s += string{chr[1]} + chr[1]; else s += string{chr[1]} + chr[2]; } else if(ask(nextstr) - s.size() == 2){ if(ask(s + chr[0] + chr[0] + chr[1] + s + chr[0] + chr[1] + chr[1]) - s.size() == 0){ if(ask(s + chr[1] + chr[0] + chr[1]) - s.size() >= 3) s += string{chr[1]} + chr[0] + chr[1]; else s += string{chr[1]} + chr[0] + chr[2]; } else if(ask(s + chr[0] + chr[0] + chr[1] + s + chr[0] + chr[1] + chr[1]) - s.size() == 1){ if(ask(s + chr[0] + chr[2] + chr[1]) - s.size() >= 3) s += string{chr[0]} + chr[2] + chr[1]; else s += string{chr[0]} + chr[2] + chr[2]; } else if(ask(s + chr[0] + chr[0] + chr[1] + s + chr[0] + chr[1] + chr[1]) - s.size() == 2){ if(ask(s + chr[0] + chr[0] + chr[2]) - s.size() >= 3) s += string{chr[0]} + chr[0] + chr[2]; else s += string{chr[0]} + chr[1] + chr[2]; } else{ if(ask(s + chr[0] + chr[0] + chr[1]) - s.size() >= 3) s += string{chr[0]} + chr[0] + chr[1]; else s += string{chr[0]} + chr[1] + chr[1]; } } else{ if(ask(s + chr[0] + chr[0] + chr[0] + s + chr[0] + chr[1] + chr[0]) - s.size() >= 3){ if(ask(s + chr[0] + chr[0] + chr[0]) - s.size() >= 3) s += string{chr[0]} + chr[0] + chr[0]; else s += string{chr[0]} + chr[1] + chr[0]; } else{ if(ask(s + chr[0] + chr[2] + chr[0]) - s.size() >= 3) s += string{chr[0]} + chr[2] + chr[0]; else s += string{chr[1]} + chr[0] + chr[0]; } } } else if(n - s.size() == 2){ string nextstr = s + chr[0] + chr[0] + s + chr[0] + chr[1] + s + chr[1] + chr[0] + s + chr[1] + chr[1]; if(ask(nextstr) - s.size() == 0) s += chr[2]; else if(ask(nextstr) - s.size() == 1){ if(ask(s + chr[0] + chr[2]) - s.size() == 2) s += string{chr[0]} + chr[2]; else s += string{chr[1]} + chr[2]; } else{ if(ask(s + chr[0] + chr[0] + s + chr[0] + chr[1]) - s.size() == 2){ if(ask(s + chr[0] + chr[0]) - s.size() == 2) s += string{chr[0]} + chr[0]; else s += string{chr[0]} + chr[1]; } else{ if(ask(s + chr[1] + chr[0]) - s.size() == 2) s += string{chr[1]} + chr[0]; else s += string{chr[1]} + chr[1]; } } } else if(n - s.size() == 1){ if(ask(s + chr[0]) - s.size() == 1) s += chr[0]; else if(ask(s + chr[1]) - s.size() == 1) s += chr[1]; else s += chr[2]; } } return s; }

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

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:44:20: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |     while(s.size() < n){
      |           ~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...