# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1031508 | ArthuroWich | Combo (IOI18_combo) | C++17 | 36 ms | 2280 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 "combo.h"
#include<bits/stdc++.h>
using namespace std;
string guess_sequence(int n) {
string s;
int v;
v = press("AB");
if (v == 2) {
s = "AB";
} else if (v == 1) {
v = press("A");
if (v == 1) {
s = "A";
} else {
s = "B";
}
} else {
v = press("XY");
if (v == 2) {
s = "XY";
} else {
v = press("X");
if (v == 1) {
s = "X";
} else {
s = "Y";
}
}
}
if (n == 1) {
return s;
} else if (s.length() == n) {
return s;
}
vector<string> alp;
for (char c : "ABXY") {
if (c != s[0]) {
string t = "";
t.push_back(c);
alp.push_back(t);
}
}
while(s.length() != n) {
int si = 0, a = 1;
while((si+1+s.length())*a <= 4*n) {
si++;
a *= 3;
}
si = min(si, n-(int)s.length());
vector<vector<string>> c(si);
c[0].push_back(s+alp[0]);
c[0].push_back(s+alp[1]);
c[0].push_back(s+alp[2]);
for (int i = 1; i < si; i++) {
for (string e : c[i-1]) {
c[i].push_back(e+alp[0]);
c[i].push_back(e+alp[1]);
c[i].push_back(e+alp[2]);
}
}
int ch = s.length()+si;
int l = 0, r = c[si-1].size()-1;
while(l < r) {
int m1 = l+(r-l+1)/3, m2 = l+2*(r-l+1)/3;
string s1 = "";
for (int i = l; i < m1; i++) {
s1 += c[si-1][i];
}
if (press(s1) == ch) {
r = m1-1;
continue;
}
s1 = "";
for (int i = m1; i < m2; i++) {
s1 += c[si-1][i];
}
if (press(s1) == ch) {
l = m1;
r = m2-1;
} else {
l = m2;
}
}
v = s.length();
for (int i = v; i < c[si-1][l].length(); i++) {
s.push_back(c[si-1][l][i]);
}
}
return s;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |