# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
127679 | hcaushi | 콤보 (IOI18_combo) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
This program tries to find a given combo move in as few guesses as possible.
It works by testing two passwords at a time and using it to deduce the three possible next passwords it should try.
It scores full marks in the IOI 2018.
*/
#include <iostream>
using namespace std;
std::string guess_sequence(int N) {
char[2*N] guess; // The string we're trying
char[N] suspicion2;
char not_next_letter;
char[2] next_letter;
guess[0] = 'A';
guess[N] = 'B';
for (int i=1; i<N; i++) {
guess[i] = 'B';
guess[i+N] = 'A';
}
char first_letter; // The first letter, if it's confirmed
int number_correct; // The most recent number of letters we got correct
int last_correct; // The previous number correct, also the highest number correct we've ever had
// Begin //
number_correct = press(guess);
if (number_correct == 0) {
guess[0] = 'X';
guess[N] = 'Y';
for (int i=1; i<N; i++) {
guess[i] = 'A';
guess[i+N] = 'A';
}
}
else {
for (int i = number_recorded; i < last_correct; i++)
{
suspicion2[i] = guess[i+N];
guess[i+N] = guess[i];
}
}
while (number_correct < N) {
last_correct = max(number_correct, last_correct);
number_correct = press(guess);
not_next_letter = guess[number_correct];
if ((first_letter == 'A' && not_next_letter == 'B') || (first_letter == 'B' && not_next_letter == 'A')) {
next_letter = {'X', 'Y'};
}
else if ((first_letter == 'A' && not_next_letter == 'X') || (first_letter == 'X' && not_next_letter == 'A')) {
next_letter = {'B', 'Y'};
}
else if ((first_letter == 'A' && not_next_letter == 'Y') || (first_letter == 'Y' && not_next_letter == 'A')) {
next_letter = {'B', 'X'};
}
else if ((first_letter == 'B' && not_next_letter == 'X') || (first_letter == 'X' && not_next_letter == 'B')) {
next_letter = {'A', 'Y'};
}
else if ((first_letter == 'B' && not_next_letter == 'Y') || (first_letter == 'Y' && not_next_letter == 'B')) {
next_letter = {'A', 'X'};
}
else {
next_letter = {'A', 'B'};
}
if (number_correct > last_correct) {
for (int i = last_correct; i < number_correct; i++) {
suspicion2[i-1] = guess[i+N-1];
suspicion2[i] = guess[i+N];
}
for (int i = number_correct; i < N; i++) {
guess[i] = next_letter[0];
guess[i+N] = next_letter[1];
}
}
else if (number_correct < last_correct) {
for (int i = last_correct; i < number_correct; i++) {
guess[i] = suspicion2[i];
guess[i+N] = suspicion2[i];
}
for (int i = number_correct; i < N; i++) {
guess[i] = next_letter[0];
guess[i+N] = next_letter[1];
}
}
else {
// Error //
return 1
}
}
for (int i=0; i < N; i++) {
suspicion1[i] = guess[i];
suspicion2[i] = guess[i+N];
}
press(suspicion1) == N ? return suspicion1 : return suspicion2;
}