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>
#define ll long long int
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
#include "combo.h"
using namespace std;
ll n,m,sum,t;
// constexpr int MAX_N = 2000;
// constexpr int MAX_NUM_MOVES = 8000;
// int N;
// std::string S;
string tut="ABXY";
string s;
char tutt;
ll tutmac;
// int num_moves;
// namespace {
// void wrong_answer(const char *MSG) {
// printf("Wrong Answer: %s\n", MSG);
// exit(0);
// }
// }
// int press(std::string p) {
// if (++num_moves > MAX_NUM_MOVES) {
// wrong_answer("too many moves");
// }
// int len = p.length();
// if (len > 4 * N) {
// wrong_answer("invalid press");
// }
// for (int i = 0; i < len; ++i) {
// if (p[i] != 'A' && p[i] != 'B' && p[i] != 'X' && p[i] != 'Y') {
// wrong_answer("invalid press");
// }
// }
// int coins = 0;
// for (int i = 0, j = 0; i < len; ++i) {
// if (j < N && S[j] == p[i]) {
// ++j;
// } else if (S[0] == p[i]) {
// j = 1;
// } else {
// j = 0;
// }
// coins = std::max(coins, j);
// }
// return coins;
// }
string f1()
{
string ss="AB";;
ll a=press(ss);
ss="AX";
ll b=press(ss);
if(a)
{
if(b)
return "A";
return "B";
}
if(b)
return "X";
return "Y";
}
string end()
{
// cout<<s<<endl;
string ss=s+"A"+s+"B";
ll a=press(ss);
ss=s+"A"+s+"X";
ll b=press(ss);
if(a==n)
{
if(b==n)
return "A";
return "B";
}
if(b==n)
return "X";
return "Y";
}
ll ask1()
{
string p="";
fo(i,0,3)
{
if(tutmac==i)
continue;
p=p+s+"A"+tut[i];
}
p=p+s+"B";
return press(p)-s.size();
}
ll ask2()
{
string p="";
fo(i,0,3)
{
if(tutmac==i)
continue;
p=p+s+"X"+tut[i];
}
p=p+s+"Y";
return press(p)-s.size();
}
void ask()
{
fo(i,0,3)
if(s[0]==tut[i])
tutmac=i;
// cout<<tutmac<<endl;
ll x=0;
if(tutmac>=2)
{
x=ask1();
ll y=2;
if(tutmac==y)
y++;
if(x==0)
{
s+=tut[y];
}
if(x==1)
s+=tut[1];
if(x==2)
s+=tut[0];
return;
}
x=ask2();
// cout<<x<<endl;
ll y=0;
if(y==tutmac)
y++;
if(x==0)
{
s+=tut[y];
}
if(x==1)
s+=tut[3];
if(x==2)
s+=tut[2];
}
string guess_sequence(int nn)
{
n=nn;
s=f1();
tutmac=s[0];
string p = s;
// cout<<s<<endl;
fo(i,2,n-1)
{
ask();
}
// cout<<s<<endl;
string xx=end();
s=s+xx;
// cout<<s<<endl;
return s;
}
// int main() {
// char buffer[MAX_N + 1];
// if (scanf("%s", buffer) != 1) {
// fprintf(stderr, "Error while reading input\n");
// exit(1);
// }
// S = buffer;
// N = S.length();
// num_moves = 0;
// std::string answer = guess_sequence(N);
// if (answer != S) {
// wrong_answer("wrong guess");
// exit(0);
// }
// printf("Accepted: %d\n", num_moves);
// return 0;
// }
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |