Submission #721811

#TimeUsernameProblemLanguageResultExecution timeMemory
721811minhcool콤보 (IOI18_combo)C++17
100 / 100
34 ms472 KiB
#include "combo.h"
#include<bits/stdc++.h>
using namespace std;

//#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 3e5 + 5;

const int oo = 1e18 + 7, mod = 1e9 + 7;

int n;
string ans;
string cand;

string guess_sequence(int N){
  n = N;  
  int ind = 3;
  if(press("AB")){
    if(press("A")){
      ind = 0;
      ans += "A";
      cand = "BXY";
    }
    else{
      ind = 1;
      ans += "B";
      cand = "AXY";
    }
  }
  else{
    if(press("X")){
      ind = 2;
      ans += "X";
      cand = "ABY";
    }
    else{
      ind = 3;
      ans += "Y";
      cand = "ABX";
    }
  }
  for(int i = 1; ;){
  	//cout << i << " " << ans << "\n";
    if(i >= (n - 1)) break;
    string temp;
    temp += ans;
	temp += cand[0];
	temp += cand[0];
    temp += ans;
	temp += cand[0];
	temp += cand[1];
    temp += ans;
	temp += cand[1];
	temp += cand[1];
    int val = press(temp);
    if(val == i){
      ans += cand[2];
      i++;
    }
    else if(val == (i + 1)){
      temp.clear();
      temp += ans + cand[1] + cand[2];
      val = press(temp);
      if(val == i){
      	ans += cand[0];
      	ans += cand[2];
	  }
      else if(val == i + 1){
      	ans += cand[1];
		ans += cand[0];
	  }
      else{
      	ans += cand[1];
      	ans += cand[2];
	  }
      i += 2;
    }
    else{
      temp.clear();
      temp += ans + cand[0] + cand[1];
      val = press(temp);
      if(val == i){
      	ans += cand[1];
      	ans += cand[1];
	  }
      else if(val == i + 1){
      	ans += cand[0];
      	ans += cand[0];
	  }
      else{
      	ans += cand[0];
      	ans += cand[1];
	  }
      i += 2;
    }
  }
  if(ans.length() < n){
    string temp = ans + cand[0];
    if(press(temp) == n) ans += cand[0];
    else{
      temp = ans + cand[1];
      if(press(temp) == n) ans += cand[1];
      else ans += cand[2];
    }
  }
  return ans;
}

Compilation message (stderr)

combo.cpp:17:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   17 | const int oo = 1e18 + 7, mod = 1e9 + 7;
      |                ~~~~~^~~
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:105:19: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  105 |   if(ans.length() < n){
      |      ~~~~~~~~~~~~~^~~
combo.cpp:25:7: warning: variable 'ind' set but not used [-Wunused-but-set-variable]
   25 |   int ind = 3;
      |       ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...