# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1172440 | eggx50000 | Combo (IOI18_combo) | C++20 | 0 ms | 0 KiB |
//#include "combo.h"
#include <string>
#include <iostream>
#include <random>
#include <assert.h>
using namespace std;
char ci[4] = {'A', 'B', 'X', 'Y'};
string S;
int N;
int press(string p) {
int len = p.length();
if (len < 0 || len > 4 * N) {
cout << "goo";
}
for (int i = 0; i < len; ++i) {
if (p[i] != 'A' && p[i] != 'B' && p[i] != 'X' && p[i] != 'Y') {
cout << "goo";
}
}
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;
}
int upr(int n, string kr){
assert(kr.size() <= 4 * n);
return press(kr);
}
string guess_sequence(int N) {
string ab = "AB";
string ret = "";
char x = 0, y = 0, z = 0;
if(upr(N, ab) >= 1){
if(upr(N, "A") == 1) ret += 'A';
else ret += 'B';
}
else{
if(upr(N, "X") == 1) ret += 'X';
else ret += 'Y';
}
for(int i = 0; i < 4; i ++){
if(ci[i] == ret[0]) continue;
if(x == 0) x = ci[i];
else if(y == 0) y = ci[i];
else z = ci[i];
}
for(int i = 2; i <= N; i ++){
if(i == N){
if(upr(N, ret + x) == N) ret += x;
else if(upr(N, ret + y) == N) ret += y;
else ret += z;
}
else{
string chk;
chk += (ret + x + x);
chk += (ret + x + y);
chk += (ret + x + z);
chk += (ret + y);
int pr = upr(N, chk);
if(pr >= i + 1) ret += x;
else if(pr == i) ret += y;
else ret += z;
}
}
//cout << ret;
return ret;
}
int main()
{
cin >> S;
N = S.size();
string kr = guess_sequence(N);
cout << (kr == S);
return 0;
}