이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "combo.h"
using namespace std;
char seq[] = {'A','B','X','Y'}; // niza so 4te mozni karakteri
string guess_sequence(int n) {
string curr;
// prvo utvrudvame prv karakter, probuvame so AB, ako dade 1, znaeme deka resnieto e ili A ili B, ako ne, ili C ili D
int ans1 = press("AB");
if (ans1 > 0) {
int ans2 = press("A");
if (ans2 > 0) curr = "A";
else curr = "B";
} else {
int ans2 = press("X");
if (ans2 > 0) curr = "X";
else curr = "Y";
}
if (n == 1) return curr; // ako ima samo eden karakter zapri tuka
for (int i = 1; i<n-1; i++) {
string query;
int ctr = 1;
char koi[3];
for (int j = 0; j<4; j++) {
if (curr[0] == seq[j]) continue; // ako karakterot sto go razgleduvame e ist so prviot, ripni go
// dodaj go karakterot sto go razgleduvame vo mozni, i vo kverito (ako e prv ili vtor), soglasno objasnuvanjeto
koi[ctr-1] = seq[j];
if (ctr == 1) query += curr+seq[j]; // za prviot razgledan karakter samo go dodavame nego
else if (ctr == 2) {
string tmp = curr+seq[j];
for (int k = 0; k<4; k++) {
if (curr[0] == seq[k]) continue;
query += tmp+seq[k]; // za vtoriot razgledan karakter go dodavame nego plus site mozni naredni
}
}
ctr++;
}
int ans = press(query);
if (ans == curr.length()) curr += koi[2];
else if (ans == curr.length()+1) curr += koi[0];
else if (ans == curr.length()+2) curr += koi[1];
// sega go znaeme sledniot karakter i moze da prodolzime
}
// posledniot karakter se utvrudva kako prviot
ans1 = press(curr + "A" + curr + "B");
if (ans1 > n-1) {
int ans2 = press(curr + "A");
if (ans2 > n-1) curr += "A";
else curr += "B";
} else {
int ans2 = press(curr + "X");
if (ans2 > n-1) curr += "X";
else curr += "Y";
}
return curr;
}
컴파일 시 표준 에러 (stderr) 메시지
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:53:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | if (ans == curr.length()) curr += koi[2];
| ~~~~^~~~~~~~~~~~~~~~
combo.cpp:54:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | else if (ans == curr.length()+1) curr += koi[0];
| ~~~~^~~~~~~~~~~~~~~~~~
combo.cpp:55:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | else if (ans == curr.length()+2) curr += koi[1];
| ~~~~^~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |