# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
308664 | bigDuck | Password (RMI18_password) | C++14 | 0 ms | 0 KiB |
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 INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll
int query(string str);
int bs(char c, string s, int n){
int l=0, r=n-s.length(), m=(l+r)/2;
while(l<r){
m=(l+r)/2;
string s0="";
for(int i=1; i<=m; i++){ s0+="a"; s0[s0.length()-1]+=(c-'a');}
string s2=s0+s;
int ln=query(s2);
if(ln!=(s2.length())){
r=m;
}
else{
l=(m+1);
}
m=(l+r)/2;
}
string s0="";
for(int i=1; i<=m; i++){ s0+="a"; s0[s0.length()-1]+=(c-'a');}
string s2=s0+s;
int ln=query(s2);
if(ln!=(s2.length())){m--;}
return m;
}
int cnt[300];
void get_cnt(int n, int s){
for(char c1='a'; c1<=('a'+s-1); c1++){
string st;
for(int i=1; i<=n; i++){
st+="a"; st[st.length()-1 ]+=(c1-'a');
}
int ln=query(st);
cnt[c1]=ln;
}
}
string guess(int n, int s){
string suf="";
get_cnt(n, s);
while( (suf.length())<n ){
vector<int> sz; sz.assign(300, 0);
for(char c1='a'; c1<=('a'+s-1); c1++){
if(cnt[c1]==0){continue;}
for(char c2='a'; c2<=('a'+s-1); c2++){
if(cnt[c2]==0){
continue;
}
string st; st="a"; st[0]+=(c1-'a'); st+=suf;
sz[c1]+=bs(c2, st, n);
}
}
int mx=0; char mc='a';
for(char c1='a'; c1<='z'; c1++){
if(sz[c1]>mx){
mc=c1; mx=sz[c1];
}
}
suf="a"+suf; suf[0]+=(mc-'a'); cnt[mc]--;
}
return suf;
}