답안 #854172

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854172 2023-09-26T09:51:32 Z allin27x Password (RMI18_password) C++17
0 / 100
275 ms 596 KB
#include <bits/stdc++.h>
using namespace std;
 
int query(string str);
 
string guess(int n, int s){
    for (int i=0; i<50001; i++){
        query("a");

    }
    mt19937 rng(time(nullptr));
    string res;
    vector<int> nc(s, 0);
    vector<int> to(s, -1);
    for (int i=0; i<s; i++) nc[i] = query(string(n,'a'+i));
    int last = -1;
    while (res.size()<n){
        string rev = res; reverse(rev.begin(), rev.end());
        vector<int> rel;
        for (int i=0; i<s; i++) 
            if (nc[i] && (i==last || to[i] == last)) rel.push_back(i);
        random_shuffle(rel.begin(), rel.end());
        int mx = rel[0];
        for (int i: rel){
            if (i== rel[0]) continue;
            if (!nc[i] || (i!=last && to[i]!=last)) continue;
            if (query(string(nc[i], 'a'+i) + string(1,'a'+mx) + rev) != nc[i] + 1 + res.size()) {
                to[mx] = i;
                mx = i;
            } else {
                to[i] = mx;
            }
        }
        nc[mx] --; res += 'a' + mx;
        last = mx;
    }
    reverse(res.begin(), res.end());
    return res;
}
 

Compilation message

password.cpp: In function 'std::string guess(int, int)':
password.cpp:17:22: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   17 |     while (res.size()<n){
      |            ~~~~~~~~~~^~
password.cpp:27:70: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |             if (query(string(nc[i], 'a'+i) + string(1,'a'+mx) + rev) != nc[i] + 1 + res.size()) {
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 266 ms 344 KB Could not guess the password with 50000 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 275 ms 596 KB Could not guess the password with 50000 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 260 ms 500 KB Could not guess the password with 50000 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 266 ms 344 KB Could not guess the password with 50000 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 266 ms 344 KB Could not guess the password with 50000 queries.
2 Halted 0 ms 0 KB -