제출 #115940

#제출 시각아이디문제언어결과실행 시간메모리
115940user202729콤보 (IOI18_combo)C++17
100 / 100
41 ms660 KiB
#include "combo.h" #include<string> #include<array> std::string guess_sequence(int N) { std::string pre; // constructed prefix so far { std::string an(N,'A'); std::string bn(N,'B'); if(press(an+bn)>0){ if(press(an)>0) pre="A"; else pre="B"; }else{ std::string xn(N,'X'); if(press(xn)>0) pre="X"; else pre="Y"; } } if(N==1)return pre; char a,b,c; // the 3 nonfirst chars { std::array<char,4> nonfirst_chars{{'A','B','X','Y'}}; auto iter=nonfirst_chars.begin(); while(pre[0]!=*iter) ++iter; std::swap(*iter,nonfirst_chars[0]); a=nonfirst_chars[1]; b=nonfirst_chars[2]; c=nonfirst_chars[3]; } while((int)pre.size()<N-1){ switch(press(pre+a+a+pre+a+b+pre+a+c+pre+b)-pre.size()){ case 0:pre+=c;break; case 1:pre+=b;break; case 2:pre+=a;break; default:__builtin_trap(); } } std::string tmp=pre+a; if(press(tmp)==N)return tmp; tmp=pre+b; if(press(tmp)==N)return tmp; return pre+c; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...