답안 #520398

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
520398 2022-01-29T18:43:40 Z Alex_tz307 Password (RMI18_password) C++17
0 / 100
490 ms 96148 KB
#include <bits/stdc++.h>

using namespace std;

struct sir {
  string s;

  sir() : s("") {}

  bool operator < (const sir &a) const {
    return s.size() > a.s.size();
  };
};

int query(string);

string guess(int n, int m) {
  priority_queue<sir> pq;
  int sum_freq = 0;
  for (int i = 0; i <= m - 1; ++i) {
    char c = i + 97;
    int freq;
    if (i <= m - 2) {
      string aux = "";
      for (int j = 0; j <= n - 1; ++j) {
        aux += c;
      }
      sum_freq += query(aux);
    } else {
      freq = n - sum_freq;
    }
    sir a;
    for (int j = 0; j <= freq - 1; ++j) {
      a.s += c;
    }
    pq.push(a);
  }
  while ((int)pq.size() >= 2) {
    sir a = pq.top();
    pq.pop();
    sir b = pq.top();
    pq.pop();
    sir c;
    while (a.s.empty() == false && b.s.empty() == false) {
      string aux = "";
      aux += c.s;
      aux += a.s[0];
      aux += b.s;
      if (query(aux) == 1 + c.s.size() + b.s.size()) {
        c.s += a.s[0];
        a.s.erase(a.s.begin());
      } else {
        c.s += b.s[0];
        b.s.erase(b.s.begin());
      }
    }
    c.s += a.s;
    c.s += b.s;
    pq.push(c);
  }
  query(pq.top().s);
}

Compilation message

password.cpp: In function 'std::string guess(int, int)':
password.cpp:49:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |       if (query(aux) == 1 + c.s.size() + b.s.size()) {
      |           ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
password.cpp:62:1: warning: no return statement in function returning non-void [-Wreturn-type]
   62 | }
      | ^
password.cpp:33:23: warning: 'freq' may be used uninitialized in this function [-Wmaybe-uninitialized]
   33 |     for (int j = 0; j <= freq - 1; ++j) {
      |                     ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 490 ms 96148 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 55 ms 18348 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 398 ms 78164 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 490 ms 96148 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 490 ms 96148 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -