제출 #84141

#제출 시각아이디문제언어결과실행 시간메모리
84141lovemathboy콤보 (IOI18_combo)C++14
100 / 100
292 ms620 KiB
#include "combo.h"
#include <bits/stdc++.h>
using namespace std;

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

string guess_sequence(int n) {
  string p = "";
  string ans = "";
  for (int i = 0; i < 4*n; i++) {
  	if (i < 2*n) p += 'A';
  	else p += 'B';
  }
  char first = 'A';
  int res = press(p);
  p = "";
  if (res > 0) {
  	for (int i = 0; i < 4*n; i++) {
  		p += 'A';
  	}
  	if (press(p) > 0) first = 'A';
  	else first = 'B';
  }
  else {
  	for (int i = 0; i < 4*n; i++) {
  		p += 'X';
  	}
  	if (press(p) > 0) first = 'X';
  	else first = 'Y';
  }
  ans += first;
  char pos[3]; int cnt = 0;
  for (int i = 0; i < 4; i++) {
  	if (all[i] == first) continue;
  	pos[cnt] = all[i]; cnt++;
  }
  for (int i = 1; i < n-1; i++) {
  	p = ans + pos[0];
  	for (int j = 0; j < 3; j++) {
  		p += ans + pos[1] + pos[j];
  	}
  	while (p.length() < 4*n) p += first;
  	int res = press(p);
  	if (res == ans.length() + 1) ans += pos[0];
  	else if (res > ans.length() + 1) ans += pos[1];
  	else ans += pos[2];
  }
  if (n != 1) {
	  if (press(ans + pos[0]) == n) ans += pos[0];
	  else {
	  	if (press(ans + pos[1]) == n) ans += pos[1];
	  	else ans += pos[2];
	  }
  }
  return ans;
}

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

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:42:22: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |    while (p.length() < 4*n) p += first;
      |           ~~~~~~~~~~~^~~~~
combo.cpp:44:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |    if (res == ans.length() + 1) ans += pos[0];
      |        ~~~~^~~~~~~~~~~~~~~~~~~
combo.cpp:45:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |    else if (res > ans.length() + 1) ans += pos[1];
      |             ~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...