제출 #648871

#제출 시각아이디문제언어결과실행 시간메모리
648871Litusiano콤보 (IOI18_combo)C++14
100 / 100
44 ms772 KiB
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include "combo.h"
using namespace std;
 
string guess_sequence(int N){
  string ans;
  int x = 1;
  if(press("AB") > 0){
    if(press("A")){
      ans+='A';
      x = 0;
    }
    else ans+='B';
  }
  else{
    if(press("X")){
      ans+='X';
      x = 2;
    }
    else{
      ans+='Y';
      x = 3;
    }
  }
  string all = "ABXY";
  string pos;
  for(int i = 0; i<all.size(); ++i){
    if(i == x) continue;
    pos+=all[i];
  }
  //cout<<pos<<endl;
  /*
  Faig una sola opcio amb 0
  dos opcions amb 1
  cap amb 2  
  */
  for(int i = 2; i<=N-1; ++i){
    string s0 = ans; s0+=pos[0];
 
    string s1,s2,s3; 
    s1 = s2 = s3 = ans;
    s1+=pos[1]; s1+=pos[0]; s2+=pos[1]; s2+=pos[1]; s3+=pos[1]; s3+=pos[2];
    string tot = s0+s1+s2+s3;
    //if(i == 2) cout<<s0<<" "<<s1<<" "<<s2<<" "<<s3<<endl;
    //cout<<s0<<"\n1"<<s1<<"\n2"<<s2<<"\n3"<<s3<<"\n"<<endl;
    //cout<<4*N<<" "<<tot.size()<<endl;
    int c = press(s0+s1+s2+s3);
    //if(i == 2) cout<<c<<" "<<i<<endl;
    if(c == i) ans+=pos[0];
    else if(c == i+1) ans+=pos[1];
    else ans+=pos[2];
  }
  for(int i = max(2,N); i<=N; ++i){
    string tot = ans; tot+=pos[0];
    tot+=ans; tot+=pos[1];
    //cout<<tot<<" "<<press(tot)<<endl;
    if(press(tot) >= i){
      tot = ans; tot+=pos[0];
      if(press(tot) >= i) ans+=pos[0];
      else ans+=pos[1];
    }
    else{
      ans+=pos[2];
    }
  }
  return ans;
}

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

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:31:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(int i = 0; i<all.size(); ++i){
      |                  ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...