답안 #1054583

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054583 2024-08-12T10:50:08 Z MrAndria Password (RMI18_password) C++14
0 / 100
1 ms 344 KB
#include <bits/stdc++.h>
using namespace std;
int query(string str);
string merge(string a,string b){
    string s="",pas="";
    int curr=b.size()-1;
    for(int i=a.size();i>0;i--){
        while(curr>=0){
            s="";
            for(int i1=0;i1<=i-1;i1++){
                s+=a[i1];
            }
            for(int i1=curr;i<=b.size()-1;i1++){
                s+=b[i1];
            }
            // cout<<s<<" "<<b.size()<<endl;
            if(query(s)==s.size()){
                pas+=b[curr];
                curr--;
            }else{
                break;
            }
        }
        pas+=a[i-1];

    }
    // cout<<curr<<endl;
    while(curr>=0){
        pas+=b[curr];
        curr--;
    }
    reverse(pas.begin(),pas.end());
    return pas;
}
string guess(int n, int s){
    cin>>n>>s;
    string s1;
    set <pair <int,string > > se;
    int l;
    for(int j=1;j<=s;j++){
        s1="";
        for(int i=1;i<=n;i++){
            s1+=char(j+'a'-1);
        }

        l=query(s1);
        s1="";
        for(int i=1;i<=l;i++){
            s1+=char(j+'a'-1);
        }
        if(s1.size())se.insert(make_pair(s1.size(),s1));
    }
    while(se.size()>=2){

        auto a=(*(se.begin()));
        se.erase(se.begin());
        auto b=(*(se.begin()));
        se.erase(se.begin());
        s1=merge(a.second,b.second);
        se.insert(make_pair(s1.size(),s1));
    }
    return (*(se.begin())).second;
}

Compilation message

password.cpp: In function 'std::string merge(std::string, std::string)':
password.cpp:13:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |             for(int i1=curr;i<=b.size()-1;i1++){
      |                             ~^~~~~~~~~~~~
password.cpp:17:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |             if(query(s)==s.size()){
      |                ~~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 0 ms 344 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 0 ms 344 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1 ms 344 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 0 ms 344 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 0 ms 344 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -