답안 #773155

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773155 2023-07-04T15:50:57 Z aykhn Password (RMI18_password) C++14
0 / 100
2 ms 552 KB
#include <bits/stdc++.h>

// author: aykhn

using namespace std;

typedef long long ll;

int query(string str);

string guess(int n, int s)
{
    string ans = "";
    int prev;

    string x = "a";
    for (int i = 0; i < s; i++)
    {
        ans = x + ans;
        int X = query(ans);
        prev = max(X, prev);
        if (!X) ans = ans.substr(1, (int)(ans.length()) - 1);

        for (int j = 1; j <= ans.length(); j++)
        {
            string asd = ans.substr(0, j);
            string assd = "";
            if (j != ans.length()) assd = ans.substr(j, (int)(ans.length()) - j);
            ans = asd;
            asd += x;
            asd += assd;
            int y = query(ans);
            if (y <= prev)
            {
                asd = ans.substr(0, j);
                if (j + 1 != ans.length()) assd = ans.substr(j + 1, (int)(ans.length()) - j - 1);
                ans = asd + assd;
            }
        }

        x[0]++;
    }

    return ans;
}

Compilation message

password.cpp: In function 'std::string guess(int, int)':
password.cpp:24:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         for (int j = 1; j <= ans.length(); j++)
      |                         ~~^~~~~~~~~~~~~~~
password.cpp:28:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |             if (j != ans.length()) assd = ans.substr(j, (int)(ans.length()) - j);
      |                 ~~^~~~~~~~~~~~~~~
password.cpp:36:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |                 if (j + 1 != ans.length()) assd = ans.substr(j + 1, (int)(ans.length()) - j - 1);
      |                     ~~~~~~^~~~~~~~~~~~~~~
password.cpp:14:9: warning: 'prev' may be used uninitialized in this function [-Wmaybe-uninitialized]
   14 |     int prev;
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 464 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 464 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 552 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 464 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 464 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -