# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
410892 | abdzag | Combo (IOI18_combo) | C++17 | 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<unordered_map>
//#include "combo.h"
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define rrep(i,a,b) for(int i=int(a);i>int(b);i--)
#define all(v) v.begin(),v.end()
#define trav(a,v) for(auto&a:v)
#define sz(a) a.size()
typedef long double ld;
using namespace std;
static const long long inf = 1e15;
typedef long long ll;
typedef unsigned long long ull;
string hidden = "";
int press(string s) {
string cur = hidden;
rrep(i, hidden.size(), -1) {
bool done = true;
rep(z, 0, s.size()-cur.size()+1) {
done = true;
rep(j, 0, cur.size()) {
if (s[z + j] != cur[j]) {
done = false;
break;
}
}
if (done)break;
}
if (done)break;
cur.pop_back();
}
return cur.size();
}
string guess_sequence(int N) {
string p = "";
string cringe = "";
vector<string> v = { "A","X","Y","B" };
rep(i, 0, 3) {
if (press(v[i])) {
cringe += v[i];
v.erase(v.begin() + i);
p += cringe;
break;
}
}
if (p == "") {
cringe += v[i];
v.erase(v.begin() + i);
p += cringe;
break;
}
ll cur = 1;
if (N == 1)return p;
rep(i, 0, N - 2) {
string nxt = p;
nxt += v[0];
nxt += p + v[1] + v[0];
nxt += p + v[1] + v[1];
nxt += p + v[1] + v[2];
int val = press(nxt);
if (val == cur + 1) {
p += v[0];
}
else if (val == cur + 2) {
p += v[1];
}
else p += v[2];
cur++;
}
rep(i, 0, 3) {
string nxt = p + v[i];
if (press(nxt) == N) {
p += v[i];
break;
}
}
return p;
}
int main() {
vector<string> v = { "A","B","X","Y" };
rep(i, 0, 4) {
vector<string> v2 = v;
v2.erase(v2.begin() + i);
do {
hidden = v[i];
rep(j, 0, 2) {
if (hidden != guess_sequence(hidden.size())) {
cout << hidden;
break;
}
hidden += v2[j];
}
} while (next_permutation(all(v2)));
}
}