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;
#pragma GCC optimize("Ofast,unroll-loops")
#define ll long long
//#define int ll
#define ull unsigned ll
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define chkmin(a,b) (a=min(a,b))
#define chkmax(a,b) (a=max(a,b))
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
//#define inf 1010000000
#define inf 4000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(vector<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(set<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(unordered_set<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(T && x) {cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);}
#else
#define bug(...) 777771449
#endif
template<typename T> void print(T && x) {cout << x << "\n";}
template<typename T, typename... S> void print(T && x, S&&... y) {cout << x << ' ';print(y...);}
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
const int maxn=5005,maxm=32,maxk=7777714;
//i_am_noob
//#define wiwihorz
int query(string str);
int cnt[26];
string letters[26];
const int david=13;
string guess(int n, int s){
string res;
memset(cnt,0,sizeof cnt);
rep(s){
string str;
rep1(j,n) str+='a'+i;
cnt[i]=query(str);
letters[i]=str;
}
vector<int> id;
rep(s) id.pb(i);
sort(all(id),[](int i, int j){return cnt[i]<cnt[j];});
for(auto t: id){
if(res.empty()){
rep(cnt[t]) res+='a'+t;
continue;
}
string str;
str+=res[0];
while(sz(str)<n) str+='a'+t;
int x=query(str)-1;
string nres;
rep(cnt[t]-x) nres+='a'+t;
int cur=0;
while(cur<sz(res)){
if(x==0){
nres+=res[cur];
cur++;
continue;
}
if(cur==sz(res)-1){
nres+=res[cur];
rep(x) nres+='a'+t;
cur++;
break;
}
if(sz(res)-cur<x*(__lg(sz(res)-cur+1)+1)){
str=res.substr(0,cur+2)+letters[t].substr(0,x);
int y=query(str)-cur-2;
nres+=res[cur];
rep(x-y) nres+='a'+t;
cur++;
x=y;
continue;
}
int l=cur+1,r=sz(res)-1;
while(l<r){
int mid=l+r>>1;
str=res.substr(0,mid+1)+letters[t].substr(0,x);
int y=query(str)-mid-1;
if(y<x) r=mid;
else l=mid+1;
}
str=res.substr(0,l+1)+letters[t].substr(0,x);
int y=query(str)-l-1;
while(cur<l) nres+=res[cur],cur++;
rep(x-y) nres+='a'+t;
x=y;
}
res=nres;
//cout << res << "\n";
}
return res;
}
Compilation message (stderr)
password.cpp: In function 'std::string guess(int, int)':
password.cpp:100:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
100 | int mid=l+r>>1;
| ~^~
# | 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... |