# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
722065 | 2023-04-11T11:28:23 Z | nguyentunglam | Password (RMI18_password) | C++17 | 0 ms | 0 KB |
#include<bits/stdc++.h> using namespace std; const int N = 5010; int cnt[N]; char a[N], b[N]; string guess(int n, int s) { vector<pair<int, char> > lst; for(int j = 0; j < s; j++) { char c = j + 'a'; string ask; for(int i = 1; i <= n; i++) ask.push_back(c); lst.emplace_back(query(ask), c); } sort(lst.begin(), lst.end()); int m; char c; tie(m, c) = lst[0]; for(int i = 1; i <= m; i++) a[i] = c; lst.erase(lst.begin()); for(auto &it : lst) { int num; char c; tie(num, c) = it; for(int i = 0; i <= m; i++) { string ask; for(int j = 1; j <= i; j++) ask.push_back(a[j]); cnt[i] = 0; while (num > 0) { ask.push_back(c); string tmp; for(int j = i + 1; j <= m; j++) tmp.push_back(a[j]); if (query(ask + tmp) > m + cnt[i]) cnt[i]++, num--; else break; } } int m2 = 0; for(int i = 0; i <= m; i++) { if (i) b[++m2] = a[i]; while (cnt[i]--) b[++m2] = c; } for(int i = 1; i <= m2; i++) a[i] = b[i]; m = m2; } string ret; for(int i = 1; i <= m; i++) ret.push_back(a[i]); return ret; }