Submission #333357

# Submission time Handle Problem Language Result Execution time Memory
333357 2020-12-05T17:07:00 Z valerikk Password (RMI18_password) C++17
10 / 100
174 ms 364 KB
#include <bits/stdc++.h>
using namespace std;

int query(string str);

void myinsert(string &str, int pos, char x) {
    string s = "";
    for (int i = 0; i <= str.size(); i++) {
        if (i < pos) s.push_back(str[i]); else {
            if (i == pos) s.push_back(x); else s.push_back(str[i - 1]);
        }
    }
    str = s;
}

void myerase(string &str, int pos) {
    string s = "";
    for (int i = 0; i < str.size(); i++) {
        if (i == pos) continue;
        s.push_back(str[i]);
    }
    str = s;
}

string guess(int n, int s) {
    string res = "";
    for (int i = 0; i < n; i++) {
        if (res.size() < i) return string(n, 'a');
        for (char x = 'a'; x < 'a' + s; x++) {
            if (res.size() < n) {
                myinsert(res, i, x);
                if (query(res) != res.size()) myerase(res, i);
            }
        }
    }
    return res;
}

Compilation message

password.cpp: In function 'void myinsert(std::string&, int, char)':
password.cpp:8:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for (int i = 0; i <= str.size(); i++) {
      |                     ~~^~~~~~~~~~~~~
password.cpp: In function 'void myerase(std::string&, int)':
password.cpp:18:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int i = 0; i < str.size(); i++) {
      |                     ~~^~~~~~~~~~~~
password.cpp: In function 'std::string guess(int, int)':
password.cpp:28:24: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |         if (res.size() < i) return string(n, 'a');
      |             ~~~~~~~~~~~^~~
password.cpp:30:28: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |             if (res.size() < n) {
      |                 ~~~~~~~~~~~^~~
password.cpp:32:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |                 if (query(res) != res.size()) myerase(res, i);
      |                     ~~~~~~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 364 KB Guessed the password with 210 queries.
2 Correct 6 ms 364 KB Guessed the password with 482 queries.
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 364 KB Returned early from guess() after 91 queries.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 174 ms 364 KB Returned early from guess() after 9457 queries.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 364 KB Guessed the password with 210 queries.
2 Correct 6 ms 364 KB Guessed the password with 482 queries.
3 Incorrect 2 ms 364 KB Returned early from guess() after 91 queries.
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 364 KB Guessed the password with 210 queries.
2 Correct 6 ms 364 KB Guessed the password with 482 queries.
3 Incorrect 2 ms 364 KB Returned early from guess() after 91 queries.
4 Halted 0 ms 0 KB -