Submission #1159704

#TimeUsernameProblemLanguageResultExecution timeMemory
1159704fryingducPassword (RMI18_password)C++17
20 / 100
74 ms476 KiB
#include <string>
#include <queue>

using namespace std;

int query(string q);

string guess(int n, int c) {
  priority_queue<pair<int, string>> pq;
  for (int i = 0; i < c; ++i) {
    string cur;
    for (int j = 0; j < n; ++j) {
      cur += char('a' + i);
    }
    int x = query(cur);
    if (x > 0) {
      cur.clear();
      for (int j = 0; j < x; ++j) {
        cur += char('a' + i);
      }
      pq.push(make_pair(x, cur));
    }
  }
  while ((int)pq.size() > 1) {
    string x = pq.top().second;
    pq.pop();
    string y = pq.top().second;
    pq.pop();
    string res;
    while (!x.empty()) {
      string g = res;
      g += x[0];
      g += y;
      if (query(g) == (int)g.size()) {
        res += x[0];
        x.erase(x.begin());
      } else {
        res += y[0];
        y.erase(y.begin());
      }
    }
    if (!y.empty()) {
      res += y;
    }
    pq.push(make_pair((int)res.size(), res));
  }
  return pq.top().second;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...