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"
using namespace std;
#define endl "\n"
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const long long MOD = 1e9+7;
const long long INF = 1e18;
int nx[4] = {0, 0, -1, 1};
int ny[4] = {1, -1, 0, 0};
ll my_rand(ll l, ll r)
{
srand(chrono::steady_clock::now().time_since_epoch().count());
ll len = r-l;
ll a = rand()%len;
ll b = rand()%len;
ll res = ((((a%len)*((RAND_MAX+1)%len))%len) + (b%len))%len;
if(res<l)
res +=l;
return res;
}
int press(string p);
string guess_sequence(int n)
{
string s = "";
string choices = "ABXY";
string p = "";
vector<bool> visited(4, false);
while(true)
{
ll x = my_rand(0, 4);
if(visited[x])
continue;
visited[x] = true;
p.pb(choices[x]);
if(press(p)==1)
{
s = p;
break;
}
p = s;
}
while(int(s.length())<n)
{
ll i = my_rand(0, 4);
if(choices[i]==s[0])
continue;
if(choices[i]==s[int(s.length())-1])
continue;
p = s;
while(int(p.length())<4*n)
{
p.pb(choices[i]);
}
ll added = press(p) - int(s.length());
p = s;
if(added>0)
{
for(int j = 0; j<added; j++)
s.pb(choices[i]);
}
else
{
char c = 'A';
for(int k = 0; k<4; i++)
{
if(choices[k]!=choices[i]&&choices[k]!=s[0]&&choices[k]!=s[int(s.length())-1])
{
c = choices[k];
break;
}
}
while(int(p.length())<4*n)
{
p.pb(c);
}
ll ad = press(p)-int(s.length());
for(int k = 0; k<ad; k++)
s.pb(c);
}
}
return s;
}
Compilation message (stderr)
combo.cpp: In function 'long long int my_rand(long long int, long long int)':
combo.cpp:26:35: warning: integer overflow in expression of type 'int' results in '-2147483648' [-Woverflow]
26 | ll res = ((((a%len)*((RAND_MAX+1)%len))%len) + (b%len))%len;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |