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 <iostream>
#include <vector>
#include <string>
#include <combo.h>
using namespace std;
string guess_sequence(int N) {
// 100 points: N + 2 calls to "press"
string p = "";
string S = "";
vector<string> v = {};
int coins = 0;
// guess 1st letter of S (num of calls to "press" = 2)
p = "AB"; coins = press(p);
if (coins >= 1) {
p = "A"; coins = press(p);
if (coins == 1) {S = "A"; v = {"B", "X", "Y"};} // 1st letter = A
else {S = "B"; v = {"A", "X", "Y"};} // 1st letter = B
}
else {
p = "X"; coins = press(p);
if (coins == 1) {S = "X"; v = {"A", "B", "Y"};} // 1st letter = X
else {S = "Y"; v = {"A", "B", "X"};} // 1st letter = Y
}
// if N = 1...
if (N == 1) {return S;}
// guess from 2nd letter to N-1 (num of calls to "press" = N-2)
while ((int)S.length() < N-1) {
int i = (int)S.length();
p = S + v[0]+v[0] + S + v[0]+v[1] + S + v[0]+v[2] + S + v[1];
// f.e. 1st = A p = SBB SBX SBY SX
coins = press(p);
if (coins == i+2) {S += v[0];} // next letter = B v[0]
else if (coins == i+1) {S += v[1];} // next letter = X v[1]
else {S += v[2];} // next letter = Y v[2]
i++;
}
// guess last letter of S (num of calls to "press" = 2)
p = S + v[0]; coins = press(p);
if (coins == N) {S += v[0];}
else {
p = S + v[1]; coins = press(p);
if (coins == N) {S += v[1];}
else {S += v[2];}
}
// total of calls to "press" = 2 + N-2 + 2 = (N + 2)
return S;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |