IOI 2018 – Combo Problem and Solution

IOI 2018 – Combo Problem and Solution

The 30th International Olympiad in Informatics was held in Tsukuba, Japan in 2018. There were two competition days, with 3 problems given to the competitors on each day. You can see Combo problem and solutions below.

Problem :

ioi2018problem1

Solution :

#include "combo.h"
#include <bits/stdc++.h>
using namespace std;

string guess_sequence(int N) {
	string p = "";
	if(press("AB") >= 1) p = press("A") ? "A" : "B";
	else p = press("X") ? "X" : "Y";
	vector<char> chr = {'A', 'B', 'X', 'Y'};
	chr.erase(find(chr.begin(), chr.end(), p[0]));
	while((int)p.size() <= N - 2){ 
		int query = press(p + chr[0] + chr[0] + p + chr[0] + chr[1] + p + chr[1] + chr[0]);
		if(query == p.size()){
			p.push_back(chr[2]);
		}
		else if(query == p.size() + 1){
			query = press(p + chr[1] + chr[2]);
			if(query == p.size()) p = p + chr[0] + chr[2];
			else if(query == p.size() + 1) p = p + chr[1] + chr[1];
			else p = p + chr[1] + chr[2];
		}
		else{
			query = press(p + chr[0] + chr[1]);
			if(query == p.size()) p = p + chr[1] + chr[0];
			else if(query == p.size() + 1) p = p + chr[0] + chr[0];
			else p = p + chr[0] + chr[1];
		}
	}
	while(p.size() != N){
		if(press(p + chr[0]) == p.size() + 1) p.push_back(chr[0]);
		else if(press(p + chr[1]) == p.size() + 1) p.push_back(chr[1]);
		else p.push_back(chr[2]);
	}
	return p;
}

Explanation :

combo-review

 47 total views,  1 views today

Post Disclaimer

The hole problem statement are given by ioinformatics.org but the solution are generated by the sltechacademy authority if any of the query regarding this post or website fill the following contact form thank you. 

Leave a Reply

Your email address will not be published. Required fields are marked *