#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define fi first
#define se second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
struct pair_hash{
size_t operator()(const pair<int,int>&x)const{
return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
}
};
int query(string str);
int Cnt[30];
int N;
bool comp(pair<string, int> x, pair<string, int> y){
if(x.fi == y.fi){
return 1;
}
string now = {};
for(int i = 1; i <= x.se; i++){
now += x.fi;
}
for(int i = y.se; i <= Cnt[y.fi[0] - 'a']; i++){
now += y.fi;
}
if(sz(now) > N){
return 0;
}
if(query(now) == sz(now)){
return 1;
}
return 0;
}
vector<pair<string, int>> vec = {};
void mergeSort(int l, int p){
if(p <= l){
return;
}
int mid = (l + p) / 2;
mergeSort(l, mid);
mergeSort(mid + 1, p);
vector<pair<string, int>> a = {};
vector<pair<string, int>> b = {};
vector<pair<string, int>> res = {};
for(int i = l; i <= p; i++){
if(i <= mid){
a.pb(vec[i]);
}else{
b.pb(vec[i]);
}
}
int wsk1 = 0;
int wsk2 = 0;
while(wsk1 < sz(a) || wsk2 < sz(b)){
if(wsk1 == sz(a)){
res.pb(b[wsk2++]);
}else if(wsk2 == sz(b)){
res.pb(a[wsk1++]);
}else{
if(comp(a[wsk1], b[wsk2])){
res.pb(a[wsk1++]);
}else{
res.pb(b[wsk2++]);
}
}
}
for(int i = 0; i < sz(res); i++){
vec[l + i] = res[i];
}
}
string guess(int n, int S){
N = n;
for(int i = 0; i < S; i++){
char curr = 'a' + i;
//cerr << curr << '\n';
string add = "f";
add[0] = curr;
string now = add;
while(query(now) == sz(now)){
now += add;
}
now.pop_back();
//cerr << i << ' ' << now << '\n';
Cnt[i] = sz(now);
for(int j = 0; j < sz(now); j++){
vec.pb(mp(add, j + 1));
}
}
mergeSort(0, sz(vec) - 1);
string s = "";
for(auto ele : vec){
s += ele.fi;
}
return s;
}
| # | 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... |