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 opt[] = {"A", "B", "X", "Y"};
vector<string> oth;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
string get_p() {
if (press(opt[0] + opt[1]) >= 1) {
if (press(opt[0]) == 1) return opt[0];
return opt[1];
} else {
if (press(opt[2]) == 1) return opt[2];
return opt[3];
}
}
string find_first() {
string p = get_p();
for (string c : opt) {
if (string(1, p[0]) != c) oth.push_back(c);
}
return p;
}
string find_two(string sd) {
shuffle(oth.begin(), oth.end(), mt19937(seed));
vector<string> cmb;
for (int i = 0; i < 2; ++i) {
cmb.push_back(oth[0] + oth[i]);
}
cmb.push_back(oth[1] + oth[0]);
string q;
for (auto x : cmb) q += sd + x;
int out = press(q) - sd.length();
if (out == 2) {
out = press(sd + oth[0] + oth[1]) - sd.length();
if (out == 2) return oth[0] + oth[1];
if (out == 1) return oth[0] + oth[0];
if (out == 0) return oth[1] + oth[0];
} else if (out == 1) {
out = press(sd + oth[1] + oth[1]) - sd.length();
if (out == 2) return oth[1] + oth[1];
if (out == 1) return oth[1] + oth[2];
if (out == 0) return oth[0] + oth[2];
} else {
return oth[2];
}
}
string find_one(string p) {
int tre = 0;
bool ok = 0;
for (string c : opt) {
if (p.length() > 0 && c == string(1, p[0])) continue;
if (ok || press(p + c) == (int)p.length() + 1) {
p += c;
break;
} else tre++;
if (p.length() > 0 && tre == 2) ok = 1;
if (p.length() == 0 && tre == 3) ok = 1;
}
return p;
}
string find_one_fast(string sd) {
string q = sd + oth[0] + sd[0];
for (int i = 0; i < 3; ++i) q += sd + oth[1] + oth[i];
int out = press(q) - sd.length();
if (out == 2) return oth[1];
if (out == 1) return oth[0];
return oth[2];
}
string guess_sequence(int N) {
oth.clear();
string p = find_first();
while ((int)p.length() + 2 <= N) {
p += find_two(p);
}
if ((int)p.length() != N) {
p = find_one(p);
}
return p;
}
/*
S'AA S'AB S'BA
2 -> AA/AB/BA
-> Kysy AB
-> 2 = AB
-> 1 = AA
-> 0 = BA
1 -> AX/BB/BX
-> Kysy BB
-> 2 = BB
-> 1 = BX
-> 0 = AX
0 -> XA/XB/XX
-> Lisää X
S'AY S'BA S'BB S'BX
-> 2 = B
-> 1 = A
-> 0 = X
*/
Compilation message (stderr)
combo.cpp: In function 'std::string find_two(std::string)':
combo.cpp:33:20: warning: control reaches end of non-void function [-Wreturn-type]
33 | vector<string> cmb;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |