제출 #479863

#제출 시각아이디문제언어결과실행 시간메모리
479863glome콤보 (IOI18_combo)C++17
100 / 100
43 ms624 KiB
#include "combo.h"
#include<bits/stdc++.h>

using namespace std;

string f(char a) {
	return string(1, a);
}

std::string guess_sequence(int N) {	
	set<char> s;
	s.insert('A');
	s.insert('B');
	s.insert('X');
	if(N == 1) {
		for (char c : s) {
			if(press(string(1, c))) {
				return string(1, c);
			}
		}
		return string(1, 'Y');
	
	}
	string ans = "";
	vector<char> y = {'A', 'B', 'X', 'Y'};
	s.insert('Y');
	char excluded;
	if(press(f(y[0]) + f(y[1]))) {
		if(press(f(y[0]))) {
			excluded = y[0];
		}
		else {
			excluded = y[1];
		}
	}
	else {
		if(press(f(y[2]))) {
			excluded = y[2];
		}
		else {
			excluded = y[3];
		}
	}
	y.clear();
	s.erase(excluded);
	for (char c : s) {
		y.push_back(c);
	}
	ans = ans + f(excluded);
	for (int i = 1; i<N; i++) {
		if(i == N - 1) {	
			bool ok = 0;
			for (int j = 0; j<2; j++) {
				if(press(ans + f(y[j])) == ans.size() + 1) {
					ans = ans + f(y[j]);
					ok = 1;
					break;
				}
			}
			if(!ok) {
				ans = ans + f(y[2]);
			}
			continue;
		}
		vector<string> checks;
		for (int j = 0; j<3; j++) {
			checks.push_back(f(y[0]) + f(y[j]));
		}
		checks.push_back(f(y[1]));
		int k = press(ans + checks[0] + ans + checks[1] + ans + checks[2] + ans + checks[3]);
		if(k == ans.size() + 2) {
			ans = ans + f(y[0]);
		}
		else if(k == ans.size() + 1) {
			ans = ans + f(y[1]);
		}
		else if(k == ans.size() + 0) {
			ans = ans + f(y[2]);
		}
	}
	return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:54:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     if(press(ans + f(y[j])) == ans.size() + 1) {
      |        ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
combo.cpp:71:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |   if(k == ans.size() + 2) {
      |      ~~^~~~~~~~~~~~~~~~~
combo.cpp:74:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |   else if(k == ans.size() + 1) {
      |           ~~^~~~~~~~~~~~~~~~~
combo.cpp:77:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |   else if(k == ans.size() + 0) {
      |           ~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...