답안 #773319

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773319 2023-07-04T21:35:04 Z TheSahib Password (RMI18_password) C++14
10 / 100
46 ms 324 KB
#include <bits/stdc++.h>
 
#define ll long long
#define pii pair<int, int>
 
using namespace std;
 
int cnt[30];
 
int query(string s);

string merge(string s1, string s2){
    int p = 0;
    string ans = s1;
    for (int i = 0; i <= s1.size() && p < s2.size(); i++)
    {
        string z = ans;
        z.insert(z.begin() + i, s2[p]);
        int b = query(z);
        if(b == z.size()){
            ans = z;
            p++;
            i -= 1;
        }
    }
    return ans;
}
 
string guess(int n, int s){
    vector<string> ss;
    for (int c = 'a'; c < 'a' + s; c++)
    {
        string a;
        for (int i = 0; i < n; i++)
        {
            a += c;
        }
        int b = query(a);
        a.erase(a.begin() + b, a.end());
        cnt[c - 'a'] = b;
        if(a.empty()) continue;
        ss.push_back(a);
    }
    while(ss.size() != 1){
        sort(ss.begin(), ss.end());
        string a = merge(ss[ss.size() - 1], ss[ss.size() - 2]);
        ss.pop_back();
        ss.pop_back();
        ss.push_back(a);
    }
    
    return ss[0];
}

Compilation message

password.cpp: In function 'std::string merge(std::string, std::string)':
password.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for (int i = 0; i <= s1.size() && p < s2.size(); i++)
      |                     ~~^~~~~~~~~~~~
password.cpp:15:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for (int i = 0; i <= s1.size() && p < s2.size(); i++)
      |                                       ~~^~~~~~~~~~~
password.cpp:20:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         if(b == z.size()){
      |            ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Guessed the password with 87 queries.
2 Correct 2 ms 208 KB Guessed the password with 156 queries.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB Returned early from guess() after 36 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 324 KB Returned early from guess() after 5291 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Guessed the password with 87 queries.
2 Correct 2 ms 208 KB Guessed the password with 156 queries.
3 Incorrect 1 ms 208 KB Returned early from guess() after 36 queries.
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Guessed the password with 87 queries.
2 Correct 2 ms 208 KB Guessed the password with 156 queries.
3 Incorrect 1 ms 208 KB Returned early from guess() after 36 queries.
4 Halted 0 ms 0 KB -