Submission #333351

# Submission time Handle Problem Language Result Execution time Memory
333351 2020-12-05T16:46:32 Z valerikk Password (RMI18_password) C++17
0 / 100
315 ms 748 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 cur = "";
    string res = "";
    for (int i = 0; i < n; i++) {
        while (true) {
            bool was = false;
            for (char x = 'a'; x < 'a' + s; x++) {
                myinsert(cur, i, x);
                if (query(cur) == cur.size()) was = true; else myerase(cur, i);
            }
            if (!was) break;
        }
        res.push_back(cur[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:33:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |                 if (query(cur) == cur.size()) was = true; else myerase(cur, i);
      |                     ~~~~~~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 364 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 364 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 315 ms 748 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 364 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 364 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -