답안 #773341

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773341 2023-07-04T22:48:33 Z aykhn Password (RMI18_password) C++14
0 / 100
17 ms 320 KB
#include <bits/stdc++.h>

// author: aykhn

using namespace std;

typedef long long ll;
#define pb push_back
#define ins insert
#define mpr make_pair

int cnt[30];
priority_queue<pair<int, string>, vector<pair<int, string>>, greater<pair<int, string>>> pq;

int query(string str);

void MERGE(string &a, string &b)
{
    int prev = query(b);

    int i = 0;

    for (int j = 0; j <= b.length() && i < a.length(); j++)
    {
        string tmp = b;
        b.ins(b.begin() + j, a[i]);
        int x = query(b);
        if (x <= prev) b = tmp;
        else i++;
    }
}

string guess(int n, int s)
{
    string tmp = "";
    for (int i = 0; i < n; i++)
    {
        tmp.pb('a');
    }
    int prev = 0;

    for (int i = 0; i < s; i++)
    {
        cnt[i] = query(tmp);
        pq.push(mpr(cnt[i], tmp.substr(0, cnt[i])));

        for (int j = 0; j < n; j++) tmp[j]++;
    }

    while (pq.size() > 1)
    {
        string A = pq.top().second;
        pq.pop();
        string B = pq.top().second;
        pq.pop();

        MERGE(A, B);

        pq.push(mpr(B.length(), B));
    }

    return pq.top().second;
}

Compilation message

password.cpp: In function 'void MERGE(std::string&, std::string&)':
password.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for (int j = 0; j <= b.length() && i < a.length(); j++)
      |                     ~~^~~~~~~~~~~~~
password.cpp:23:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for (int j = 0; j <= b.length() && i < a.length(); j++)
      |                                        ~~^~~~~~~~~~~~
password.cpp: In function 'std::string guess(int, int)':
password.cpp:40:9: warning: unused variable 'prev' [-Wunused-variable]
   40 |     int prev = 0;
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB Returned early from guess() after 76 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB Returned early from guess() after 43 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 320 KB Returned early from guess() after 1791 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB Returned early from guess() after 76 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB Returned early from guess() after 76 queries.
2 Halted 0 ms 0 KB -