제출 #918915

#제출 시각아이디문제언어결과실행 시간메모리
918915vjudge1Password (RMI18_password)C++17
100 / 100
124 ms1480 KiB
#include <bits/stdc++.h>
using namespace std;

int query(string s);

string join(string x, string y)
{
    int i = x.size();
    int j = y.size() - 1;

    string res = "";
    
    while(i > 0)
    {
        while(j >= 0)
        {
            string q = x.substr(0, i) + y.substr(j);
            if(query(q) == q.size())
            {
                res += y[j--];
            }
            else break;
        }
        res += x[i - 1];
        i--;
    }

    while(j >= 0)
        res += y[j--];

    reverse(res.begin(), res.end());

    return res;
}

string guess(int n, int s)
{
    priority_queue<pair<int, string>, vector<pair<int, string>>, greater<pair<int, string>>> pq;
    for(int i = 0 ; i < s; i++)
    {
        string x = "";
        for(int j = 0; j < n; j++)
            x += char('a' + i);

        int cnt = query(x);
        x.clear();
        
        while(cnt--)
            x += char('a' + i);
        
        if(cnt)pq.push({x.size(), x});
    }

    while(pq.size() > 1)
    {
        string a = pq.top().second; pq.pop();
        string b = pq.top().second; pq.pop();

        string r = join(a, b);
        pq.push({r.size(), r});
    }

    return pq.top().second;
}

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

password.cpp: In function 'std::string join(std::string, std::string)':
password.cpp:18:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |             if(query(q) == q.size())
      |                ~~~~~~~~~^~~~~~~~~~~
#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...