답안 #709262

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
709262 2023-03-13T09:52:16 Z Halogen Password (RMI18_password) C++14
0 / 100
4 ms 556 KB
#include <bits/stdc++.h>

using namespace std;

int query(string q);

string obtainstr(string s, int m, char i) {
    if (m <= 0) return i + s;
    if (m >= s.length()) return s + i;
    return s.substr(0, m) + i + s.substr(m);
}

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

    int amt[s + 5];
    for (int i = 0; i < s; i++) {
        amt[i] = query(string(n, 'a' + i));
    }

    for (int i = 0; i < s; i++) if (amt[i]) {
        ans = string(amt[i], 'a' + i);
        break;
    }

    char cur = ans[0] - 'a' + 1;
    while (cur < s) {
        int l = 0, r = ans.length();
        if (amt[cur] <= 0) {++cur; continue;}

        while(l <= r) {
            int m = l+r >> 1;
            int res = query(obtainstr(ans, m, 'a' + cur));

            if (res >= ans.length() + 1) l = m + 1;
            else r = m - 1;
        }

        --amt[cur];
        ans = ans.substr(0, r) + char('a' + cur) + ans.substr(r);
    }

    return ans;
}

Compilation message

password.cpp: In function 'std::string obtainstr(std::string, int, char)':
password.cpp:9:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     if (m >= s.length()) return s + i;
      |         ~~^~~~~~~~~~~~~
password.cpp: In function 'std::string guess(int, int)':
password.cpp:29:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   29 |         if (amt[cur] <= 0) {++cur; continue;}
      |                 ^~~
password.cpp:32:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |             int m = l+r >> 1;
      |                     ~^~
password.cpp:35:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |             if (res >= ans.length() + 1) l = m + 1;
      |                 ~~~~^~~~~~~~~~~~~~~~~~~
password.cpp:39:15: warning: array subscript has type 'char' [-Wchar-subscripts]
   39 |         --amt[cur];
      |               ^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 464 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 556 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 3 ms 464 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 464 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -