Submission #1118485

# Submission time Handle Problem Language Result Execution time Memory
1118485 2024-11-25T14:41:22 Z Ciprian Password (RMI18_password) C++14
0 / 100
12 ms 712 KB
#include <bits/stdc++.h>
using namespace std;
int query(string s);
vector<char>c;
map<char, int>cnt;
char divide(string pref,int l, int r){
    if(l==r){
        char x;
        for(int i=0; i<l; i++){
            if(!cnt[c[i]])continue;
            x=c[i];
        }for(int i=c.size()-1; i>r; i--){
            if(!cnt[c[i]])continue;
            x=c[i];
        }if(query(pref+c[l]+string(cnt[x], x))==pref.size()+cnt[x]+1)return c[l];
        return '1';
    }else{
        int mid=(l+r)/2;
        char w=divide(pref, mid+1, r);
        if(w!='1'){
            return w; 
        }return divide(pref, l, mid);
    }
}
string guess(int n, int s){
    char a='a';
    
    for(int j=1; j<=s; j++){
        cnt[a]=query(string(n, a));
        if (cnt[a]) c.push_back(a);
        a++;
    }
    string w="";
    for(int i=1; i<=n; i++){
        int r=0;
        char x=divide(w, 0, c.size()-1);
        w+=x;
        cnt[x]--;
        
    }
    
    return w;
}

Compilation message

password.cpp: In function 'char divide(std::string, int, int)':
password.cpp:15:47: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |         }if(query(pref+c[l]+string(cnt[x], x))==pref.size()+cnt[x]+1)return c[l];
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
password.cpp: In function 'std::string guess(int, int)':
password.cpp:35:13: warning: unused variable 'r' [-Wunused-variable]
   35 |         int r=0;
      |             ^
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 352 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 448 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 12 ms 712 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 352 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 352 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -