Submission #552380

#TimeUsernameProblemLanguageResultExecution timeMemory
552380ctphongCombo (IOI18_combo)C++14
100 / 100
40 ms656 KiB
#include<bits/stdc++.h>
#include "combo.h"
using namespace std;
#define fto(i,a,b) for(int i = a; i <= b; ++i)

// int press(string s) {
// 	cout << s << endl;
// 	fflush(stdout);
// 	int gt; cin >> gt;
// 	return gt;
// }

string check;

string build(string s) {
	string ans = s+check[0];
	int l = check.length();
	fto (i, 0, (int)l-1) ans = ans + s+check[1]+check[i];
	return ans;
}

string last(string s) {
	if (press(s+check[0]+s+check[1]) == s.length()) {
		return s+check[2];
	} else {
		if (press(s+check[1]) == s.length()) return s+check[0];
		return s+check[1];
	}
	return "0.0";
}

char fir() {
	int tmp = press("AB");
	if (tmp == 0) {
		tmp = press("X");
		if (tmp == 1) return 'X';
		return 'Y';  
	} else {
		tmp = press("A");
		if (tmp == 1) return 'A';
		return 'B';
	}
	return '.';
}

string guess_sequence(int n) {
	string s;
	check = "ABXY";
	char gt = fir(); s = gt;
	fto (i, 0, (int)check.length()-1) {
		if (gt == check[i]) {
			check.erase(check.begin()+i);
			break;
		}
	}
	fto (i, 2, n-1) {
		int tmp = press(build(s));
		if (tmp == s.length()) s = s + check[2];
		else if (tmp == s.length()+1) s = s + check[0];
		else if (tmp == s.length()+2) s = s + check[1]; 	
	}
	if (n != 1) s = last(s);
	return s;
}

Compilation message (stderr)

combo.cpp: In function 'std::string last(std::string)':
combo.cpp:23:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  if (press(s+check[0]+s+check[1]) == s.length()) {
      |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
combo.cpp:26:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |   if (press(s+check[1]) == s.length()) return s+check[0];
      |       ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:58:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |   if (tmp == s.length()) s = s + check[2];
      |       ~~~~^~~~~~~~~~~~~
combo.cpp:59:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   else if (tmp == s.length()+1) s = s + check[0];
      |            ~~~~^~~~~~~~~~~~~~~
combo.cpp:60:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   else if (tmp == s.length()+2) s = s + check[1];
      |            ~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...