# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
988266 |
2024-05-24T11:41:17 Z |
Wane |
Combo (IOI18_combo) |
C++14 |
|
1 ms |
596 KB |
#include <bits/stdc++.h>
#include "combo.h"
//std::string guess_sequence(int N);
//extern int press(std::string p);
using namespace std;
/*
constexpr int MAX_N = 2000;
constexpr int MAX_NUM_MOVES = 8000;
void wrong_answer(const char *MSG) {
printf("Wrong Answer: %s\n", MSG);
exit(0);
}
std::string S;
int N;
int num_moves;
int press(std::string p) {
if (++num_moves > MAX_NUM_MOVES) {
wrong_answer("too many moves");
}
int len = p.length();
if (len > 4 * N) {
wrong_answer("invalid press");
}
for (int i = 0; i < len; ++i) {
if (p[i] != 'A' && p[i] != 'B' && p[i] != 'X' && p[i] != 'Y') {
wrong_answer("invalid press");
}
}
int coins = 0;
for (int i = 0, j = 0; i < len; ++i) {
if (j < N && S[j] == p[i]) {
++j;
} else if (S[0] == p[i]) {
j = 1;
} else {
j = 0;
}
coins = std::max(coins, j);
}
return coins;
}
*/
std::string guess_sequence(int N) {
string S;
// 1. Get first element (2 press)
int res = press("AB");
if (res == 0) { // It means X or Y
res = press("X");
if (res == 0) S += "Y";
else S += "X";
}
else {
res = press("A");
if (res == 0) S += "B";
else S += "A";
}
//cout << "Guess: " << S << '\n';
// 2. Get second to N - 1 element ( N - 2 press)
char d[5] = "ABXY";
for (int i = 1; i < N - 1; i++) { // first to N - 1, we cannot send exceeding length of 4N
char x = 0, y = 0, z = 0;
for (int j = 0; j < 4; j++) {
if (d[j] == S[0]) continue;
if (x == 0) x = d[j];
else if (y == 0) y = d[j];
else z = d[j];
}
// We can determine i'th char by using this method:
// use delimeter as FIRST CHAR AS THEY DO NOT SHOW OFF ANYMORE
// ALSO IT IS FIRST OF STRING, it stands special
// SxxSxySxzSz
// -> if 2: it has x for first, because we used all x, y, z.
// -> if 1: it has z for first
// -> if 0: it has y for first
string payload = S + x + x + S + x + y + S + x + z + S + z;
res = press(payload);
if (res == S.size() + 2) {
S += x;
}
else if (res == S.size() + 1) {
S += z;
} else {
S += y;
}
//cout << "Guess: " << S << '\n';
}
// 3. Get Last element (2 press)
for (int j = 0; j < 4; j++) {
if (d[j] == S[0]) continue;
if (j == 3) {
S += d[j];
return S;
}
res = press(S + d[j]);
if (res == N) {
S += d[j];
return S;
}
}
cout << "????" << '\n';
return S;
}
/*
int main() {
cin >> N >> S;
cout << guess_sequence(N) << '\n';
}
*/
Compilation message
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:90:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | if (res == S.size() + 2) {
| ~~~~^~~~~~~~~~~~~~~
combo.cpp:93:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | else if (res == S.size() + 1) {
| ~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
540 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Wrong Answer: wrong guess. |
2 |
Halted |
0 ms |
0 KB |
- |