제출 #1230161

#제출 시각아이디문제언어결과실행 시간메모리
1230161fauntleroy콤보 (IOI18_combo)C++20
컴파일 에러
0 ms0 KiB
#include <iostream>
#include <cstdio>
#include <vector>
#include <array>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <limits>
#include <tuple>
#include <stack>
#include <bitset>
#include <cstring>
#include <sstream>
#include <functional>
#include <random>
#include "combo.h"
using namespace std;

string guess_sequence(int N) {
	string ans;
	for (char c : {'A', 'B', 'X'}) {
		if (press(string(1, c))) {
			ans.push_back(c);
			break;
		}
	}
	if (!ans.size())
		ans.push_back('Y');

	if (N == 1)
		return ans;

	char p[3];
	int k = 0;
	for (char c : {'A', 'B', 'X', 'Y'})
		if (c != ans[0])
			p[k++] = c;

	for (int i = 1; i < N - 1; i++) {
		string ask;
		ask += ans; ask += p[0];
		ask += ans; ask += p[1]; ask += p[0];
		ask += ans; ask += p[1]; ask += p[1];
		ask += ans; ask += p[1]; ask += p[2];
		int q = press(ask);
		if (q == ans.size() + 2)
			ans.push_back(p[1]);
		else if (q == ans.size() + 1)
			ans.push_back(p[0]);
		else
			ans.push_back(p[2]);
	}
	string k = ans + p[0] + ans + p[1];
	if (press(k) == N - 1)
		ans += p[2];
	else if (press(ans + p[0]) == N - 1)
		ans += p[1];
	else
		ans += p[0];

	return ans;
}

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

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:61:16: error: conflicting declaration 'std::string k'
   61 |         string k = ans + p[0] + ans + p[1];
      |                ^
combo.cpp:42:13: note: previous declaration as 'int k'
   42 |         int k = 0;
      |             ^
combo.cpp:62:19: error: could not convert 'k' from 'int' to 'std::string' {aka 'std::__cxx11::basic_string<char>'}
   62 |         if (press(k) == N - 1)
      |                   ^
      |                   |
      |                   int