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>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
using namespace std;
#define pb push_back
#define nl '\n'
#define fore(i, y) for(int i = 0; i < y; i++)
#define forr(i, x, y) for(int i = x;i<=y;i++)
#define forn(i, y, x) for(int i = y; i >= x; i--)
using namespace std;
int query(string q) ;
string comb(string a , string b)
{
if(b.empty())
return a;
if(a.empty())
return b;
string cur = "";
vector<string> suf;
forn(i , (int)b.size() - 1 , 0)
{
cur+=b[i];
string rcur = cur;
reverse(rcur.begin() , rcur.end());
suf.pb(rcur);
}
reverse(suf.begin() , suf.end());
suf.pb("");
string res = "";
int ptr = 0;
forr(i , 0 , (int)b.size())
{
if(ptr == (int)a.size())
{
if(i < (int)b.size())
res+=b[i];
continue;
}
string beg = "";
beg+=a[ptr];
string new_res = res + beg + suf[i];
while(query(new_res) == (int)new_res.size())
{
res = res + beg;
ptr++;
if(ptr == (int)a.size())
break;
beg = "";
beg+=a[ptr];
new_res = res + beg + suf[i];
}
if(i < (int)b.size())
res+=b[i];
}
return res;
}
string get(int l , int r , int &N)
{
if(l == r)
{
string str = string(N , (char)('a' + l));
int L = query(str);
return string(L , (char)('a' + l));
}
int mid = (l + r)/2;
string a = get(l , mid , N) , b = get(mid + 1 , r , N);
return comb(a , b);
}
string guess(int N, int S)
{
return get(0 , S - 1 , N);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |