# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
228517 | chctxdy68 | Combo (IOI18_combo) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <combo.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
char cc[] = {'A', 'B', 'X', 'Y'};
bool marked[4];
string guess_sequence(int n){
char f;
if (press("AB") == 0){
if (press("X") == 0) f = 'Y';
else f = 'X';
}
else{
if (press("A") == 0) f = 'B';
else f = 'A';
}
for (ll i = 0; i < 4; i++){
if (cc[i] == f) marked[i] = 1;
}
string prefix; prefix.pb(f);
char b = '?', x = '?';
for (ll i = 0; i < 4; i++){
if (!marked[i]){
if (b == '?') b = cc[i];
else x = cc[i];
}
}
for (ll i = 1; i < n - 1; i++){
string q;
string qb = prefix; qb.pb(b);
for (ll j = 0; j < 4; j++){
if (!marked[j]){
q += qb; q.pb(cc[j]);
}
}
q += prefix; q.pb(x);
if (q > 4 * n.length()) exit(-1);
ll cnt = press(q);
if (cnt == prefix.length() + 2) prefix.pb(b);
else if (cnt == prefix.length() + 1) prefix.pb(x);
else{
for (ll j = 0; j < 4; j++){
if ((!marked[j]) && (cc[j] != b) && (cc[j] != x)) prefix.pb(cc[j]);
}
}
}
string q = prefix; q.pb('A'); q += prefix; q.pb('B');
if (press(q) > prefix.length()){
q = prefix; q.pb('A');
if (press(q) > prefix.length()) prefix.pb('A');
else prefix.pb('B');
}
else{
q = prefix; q.pb('X');
if (press(q) > prefix.length()) prefix.pb('X');
else prefix.pb('Y');
}
return prefix;
}