제출 #331745

#제출 시각아이디문제언어결과실행 시간메모리
331745dolphingarlicPassword (RMI18_password)C++14
100 / 100
283 ms888 KiB
#include <string>
using namespace std;

extern int query(string str);

string solve(int l, int r, int n) {
    if (l == r) {
        string to_guess = "";
        for (int i = 0; i < n; i++) to_guess += 'a' + l;
        int len = query(to_guess);
        return string(len, 'a' + l);
    } else {
        int mid = (l + r) / 2;
        string a = solve(l, mid, n), b = solve(mid + 1, r, n);
        int a_ptr = 0, b_ptr = 0;
        string known = "";
        while (a_ptr < a.size() && b_ptr < b.size()) {
            string to_guess = known + a[a_ptr] + b.substr(b_ptr);
            int prev_len = known.size() + b.size() - b_ptr;
            if (query(to_guess) > prev_len) known += a[a_ptr++];
            else known += b[b_ptr++];
        }
        if (a_ptr < a.size()) known += a.substr(a_ptr);
        else known += b.substr(b_ptr);
        return known;
    }
}

string guess(int n, int s) { return solve(0, s - 1, n); }

컴파일 시 표준 에러 (stderr) 메시지

password.cpp: In function 'std::string solve(int, int, int)':
password.cpp:17:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |         while (a_ptr < a.size() && b_ptr < b.size()) {
      |                ~~~~~~^~~~~~~~~~
password.cpp:17:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |         while (a_ptr < a.size() && b_ptr < b.size()) {
      |                                    ~~~~~~^~~~~~~~~~
password.cpp:23:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         if (a_ptr < a.size()) known += a.substr(a_ptr);
      |             ~~~~~~^~~~~~~~~~
#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...