답안 #855661

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855661 2023-10-01T16:09:03 Z uomoproteina Password (RMI18_password) C++14
20 / 100
237 ms 1212 KB
#include <bits/stdc++.h>

using namespace std;

string str = "";
string ans = "";

int query(string s);

bool add(string s)
{
    int ret = query(s);
    return ret == str.size() + ans.size() + 1; 
}

void solve(int N, int S)
{
    if (ans.size() + str.size() == N) return;
    bool found = false;
    for (int i = 0; i < S && !found; i++)
    {   
        if (add(str + char(i + (int)('a')) + ans)) 
        {
            str += char(i + (int)('a'));
            found = true;
        }
    }
    if (!found && str.size())
    {
        reverse(ans.begin(), ans.end());
        ans += str.back();
        reverse(ans.begin(), ans.end());
        str.pop_back();
    }
}

string guess(int n, int s)
{
    while (ans.size() + str.size() < n)
    {
        solve(n, s);
    }
    return str + ans;
}

Compilation message

password.cpp: In function 'bool add(std::string)':
password.cpp:13:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     return ret == str.size() + ans.size() + 1;
      |            ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
password.cpp: In function 'void solve(int, int)':
password.cpp:18:33: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   18 |     if (ans.size() + str.size() == N) return;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
password.cpp: In function 'std::string guess(int, int)':
password.cpp:39:36: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |     while (ans.size() + str.size() < n)
      |            ~~~~~~~~~~~~~~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Guessed the password with 330 queries.
2 Runtime error 4 ms 432 KB Execution killed with signal 13
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Guessed the password with 166 queries.
2 Correct 1 ms 344 KB Guessed the password with 306 queries.
3 Correct 1 ms 344 KB Guessed the password with 284 queries.
4 Correct 3 ms 344 KB Guessed the password with 668 queries.
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 1212 KB Guessed the password with 20171 queries.
2 Correct 148 ms 1204 KB Guessed the password with 29527 queries.
3 Correct 199 ms 1196 KB Guessed the password with 44816 queries.
4 Incorrect 237 ms 1208 KB Could not guess the password with 50000 queries.
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Guessed the password with 330 queries.
2 Runtime error 4 ms 432 KB Execution killed with signal 13
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Guessed the password with 330 queries.
2 Runtime error 4 ms 432 KB Execution killed with signal 13
3 Halted 0 ms 0 KB -