Submission #138381

#TimeUsernameProblemLanguageResultExecution timeMemory
138381LawlietCombo (IOI18_combo)C++14
100 / 100
64 ms1000 KiB
#include <bits/stdc++.h>
#include "combo.h"

using namespace std;

char buttons[] = {'A' , 'B' , 'X' , 'Y'};

int N;

string S;
string remain;

/*int press(string p)
{
	printf("-> %s\n",p.c_str());

	int a;
	scanf("%d",&a);

	return a;
}*/

void getFirstLetter()
{
	if( press("AB") >= 1 )
	{
		if(press("A") == 1) S = "A";
		else S = "B";
	}
	else
	{
		if(press("X") == 1) S = "X";
		else S = "Y";
	}
}

string guess_sequence(int n)
{
	N = n;

	getFirstLetter();

	if(N == 1) return S;

	for(int g = 0 ; g < 4 ; g++)
		if(buttons[g] != S[0])
			remain.push_back( buttons[g] );

	for(int g = 1 ; g < N - 1 ; g++)
	{
		string cur;

		for(int h = 0 ; h < 3 ; h++)
			cur = cur + S + remain[0] + remain[h];

		cur = cur + S + remain[1];

		int aux = press( cur );

		if(aux == S.size()) S = S + remain[2];
		if(aux == S.size() + 1) S = S + remain[1];
		if(aux >= S.size() + 2) S = S + remain[0];
	} 

	if(press(S + remain[0]) == N) return S + remain[0];
	if(press(S + remain[1]) == N) return S + remain[1];
	return S + remain[2];
}

/*int main()
{
	int nn;
	scanf("%d",&nn);

	printf("%s\n",guess_sequence(nn).c_str());
}*/

Compilation message (stderr)

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:60:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   if(aux == S.size()) S = S + remain[2];
      |      ~~~~^~~~~~~~~~~
combo.cpp:61:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   if(aux == S.size() + 1) S = S + remain[1];
      |      ~~~~^~~~~~~~~~~~~~~
combo.cpp:62:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |   if(aux >= S.size() + 2) S = S + remain[0];
      |      ~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...