| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1338837 | SmuggingSpun | Password (RMI18_password) | C++17 | 0 ms | 0 KiB |
#include<bits/stdc++.h>
using namespace std;
int query(string q);
string guess(int n, int s){
vector<int>cnt(s);
auto small_solve = [&] (vector<int>ord){
string ans = "";
for(int& c : ord){
vector<int>f(ans.size(), 0);
for(int p = 0; p < ans.size() && cnt[c] > 0; p++){
f[p] = cnt[c];
for(int k = 1, exp = ans.size(); k <= cnt[c]; k++){
string temp = ans.substr(0, p) + string(k, 'a' + c) + ans.substr(p, int(ans.size()) - p);
if(query(temp) != ++exp){
f[p] = k - 1;
break;
}
}
cnt[c] -= f[p];
}
string nans = "";
for(int p = 0; p < ans.size(); nans += ans[p++]){
nans += string(f[p], 'a' + c);
}
swap(ans, nans);
ans += string(cnt[c], 'a' + c);
}
return ans;
}
vector<int>ord(n);
for(int i = 0; i + 1 < s; i++){
cnt[ord[i] = i] = query(string(n, 'a' + i));
}
cnt[ord[s - 1] = s - 1] = n - accumulate(cnt.begin(), prev(cnt.end()), 0);
sort(ord.begin(), ord.end(), [&] (int i, int j){
return cnt[i] < cnt[j];
});
vector<int>part;
for(int i = 0; i < s; i += 2){
part.push_back(ord[i]);
}
string ans = small_solve(part);
part.clear();
for(int i = 1; i < s; i += 2){
part.push_back(ord[i]);
}
string other = small_solve(part);
int i = 0;
for(int p = 0; p < ans.size(); p++){
for(; i < other.size(); i++, p++){
string next_ans = ans.substr(0, p) + other[i] + ans.substr(p, int(ans.size()) - p);
if(query(next_ans) != next_ans.size()){
break;
}
swap(ans, next_ans);
}
}
while(i < other.size()){
ans += other[i++];
}
return ans;
}