Submission #293645

#TimeUsernameProblemLanguageResultExecution timeMemory
293645shrek12357Combo (IOI18_combo)C++14
100 / 100
56 ms712 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include "combo.h"
using namespace std;
 
string guess(string cur, string c1, string c2, string c3) {
	string temp = cur + c1 + cur + c2 + c1 + cur + c2 + c2 + cur + c2 + c3;
	int val = press(temp);
	if (val == cur.size()) {
		return cur + c3;
	}
	if (val == cur.size() + 1) {
		return cur + c1;
	}
	return cur + c2;
}
 
string guess_sequence(int n) {
	string ans = "";
	bool a = false, b = false, x = false, y = false;
	if (press("AB") != 0) {
		if (press("A") == 1) {
			ans += "A";
			a = true;
		}
		else {
			ans += "B";
			b = true;
		}
	}
	else {
		if (press("X") == 1) {
			ans += "X";
			x = true;
		}
		else {
			ans += "Y";
			y = true;
		}
	}
	for (int i = 1; i < n - 1; i++) {
		if (a) {
			ans = guess(ans, "B", "X", "Y");
		}
		if (b) {
			ans = guess(ans, "A", "X", "Y");
		}
		if (x) {
			ans = guess(ans, "A", "B", "Y");
		}
		if (y) {
			ans = guess(ans, "A", "B", "X");
		}
	}
  	if(ans.size() == n){
      return ans;
    }
	if (press(ans + "A" + ans + "B") == n) {
		if (press(ans + "A") == n) {
			return ans + "A";
		}
		return ans + "B";
	}
	else {
		if (press(ans + "X") == n) {
			return ans + "X";
		}
		return ans + "Y";
	}
}

Compilation message (stderr)

combo.cpp: In function 'std::string guess(std::string, std::string, std::string, std::string)':
combo.cpp:17:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  if (val == cur.size()) {
      |      ~~~~^~~~~~~~~~~~~
combo.cpp:20:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  if (val == cur.size() + 1) {
      |      ~~~~^~~~~~~~~~~~~~~~~
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:63:18: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   63 |    if(ans.size() == n){
      |       ~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...