Submission #709158

# Submission time Handle Problem Language Result Execution time Memory
709158 2023-03-13T07:05:00 Z beepbeepsheep Password (RMI18_password) C++17
10 / 100
110 ms 708 KB
#include <bits/stdc++.h>
using namespace std;
int arr[26];
int query(string s);
string build(string s, char c, int pos){
    string ret="";
    for (int i=0;i<pos;i++){
        ret+=s[i];
    }
    ret+=c;
    for (int i=pos;i<s.size();i++){
        ret+=s[i];
    }
    return ret;
}
string mrg(string a, string b){
    if (a.size()>b.size()) swap(a,b);
    if (a=="") return b;
    string ans=b;
    int l=0,r=ans.size()+1,m;
    for (int i=0;i<a.size();i++){
        l=0,r=ans.size()+1;
        while (l!=r-1){
            m=(l+r)>>1;
            string test=build(ans,a[i],m);
            int res=query(test);
            if (res==test.length()){
                l=m;
                break;
            }
            if (res<=m) r=m;
            else l=m;
        }
        ans=build(ans,a[i],l);
        cerr<<ans<<endl;
    }
    return ans;
}
string dup(char c, int n){
    string ret="";
    for (int i=0;i<n;i++) ret+=c;
    return ret;
}
string guess(int n, int s){
    for (int i=0;i<s;i++){
        arr[i]=query(dup(i+'a',n));
    }
    string ans="";
    for (int i=0;i<s;i++){
        ans=mrg(ans,dup(i+'a',arr[i]));
    }
    return ans;
}

Compilation message

password.cpp: In function 'std::string build(std::string, char, int)':
password.cpp:11:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for (int i=pos;i<s.size();i++){
      |                    ~^~~~~~~~~
password.cpp: In function 'std::string mrg(std::string, std::string)':
password.cpp:21:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (int i=0;i<a.size();i++){
      |                  ~^~~~~~~~~
password.cpp:27:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |             if (res==test.length()){
      |                 ~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Guessed the password with 48 queries.
2 Correct 2 ms 208 KB Guessed the password with 85 queries.
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 208 KB Returned early from guess() after 94 queries.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 110 ms 708 KB Returned early from guess() after 7124 queries.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Guessed the password with 48 queries.
2 Correct 2 ms 208 KB Guessed the password with 85 queries.
3 Incorrect 2 ms 208 KB Returned early from guess() after 94 queries.
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Guessed the password with 48 queries.
2 Correct 2 ms 208 KB Guessed the password with 85 queries.
3 Incorrect 2 ms 208 KB Returned early from guess() after 94 queries.
4 Halted 0 ms 0 KB -