Submission #557382

# Submission time Handle Problem Language Result Execution time Memory
557382 2022-05-05T08:58:11 Z FatihSolak Password (RMI18_password) C++17
50 / 100
1786 ms 159000 KB
#include <bits/stdc++.h>
using namespace std;
int query(string str);
// string password;
// int query(string q) {
//   int len = q.size();
//   int i = 0, j = 0, plen = password.size();
//   while (i < plen && j < len) {
//     while ((i < plen) && (password[i] != q[j])) {
//       i++;
//     }
//     if (i < plen) {
//       i++;
//       j++;
//     }
//   }
//   return j;
// }
map<string,int> mp;
int myquery(string s){
    if(mp.count(s))return mp[s];
    return mp[s] = query(s);
}
string guess(int n, int s){
    vector<int> cnt(s);
    vector<int> used(s);
    for(int i = 0;i<s;i++){
        string tmp = "";
        for(int j = 0;j<n;j++)
            tmp += (char) (i + 'a');
        //cout << tmp << endl;
        cnt[i] = myquery(tmp);
    }
    string res = "";
    for(int x = n-1;x>=0;x--){
        int val = 0;
        while(cnt[val] == 0)
            val++;
        for(int i = val+1;i<s;i++){
            if(cnt[i] == 0)continue;
            string tmp = "";
            for(int j = 0;j<cnt[val];j++)
                tmp += (char) (val + 'a');
            while(tmp.size() < n)
                tmp += (char) (i + 'a');
            if(myquery(tmp) >= cnt[val] + used[i] + 1){
                val = i;
            }
        }
        res += (char)(val + 'a');
        used[val]++;
        cnt[val]--;
        //cout << res << endl;
    }
    reverse(res.begin(),res.end());
    return res;
}
// int main(){
//     #ifdef Local
//         freopen("in.txt","r",stdin);
//         freopen("out.txt","w",stdout);
//     #endif
//     int n,s;
//     cin >> n >> s;
//     cin >> password;
//     guess(n,s);
// }

Compilation message

password.cpp: In function 'std::string guess(int, int)':
password.cpp:44:30: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |             while(tmp.size() < n)
      |                   ~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Guessed the password with 86 queries.
2 Correct 2 ms 300 KB Guessed the password with 154 queries.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Guessed the password with 27 queries.
2 Correct 3 ms 208 KB Guessed the password with 103 queries.
3 Correct 1 ms 208 KB Guessed the password with 17 queries.
4 Correct 3 ms 300 KB Guessed the password with 133 queries.
# Verdict Execution time Memory Grader output
1 Correct 120 ms 4264 KB Guessed the password with 3770 queries.
2 Correct 285 ms 12984 KB Guessed the password with 9261 queries.
3 Correct 344 ms 16544 KB Guessed the password with 9839 queries.
4 Correct 728 ms 37744 KB Guessed the password with 18313 queries.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Guessed the password with 86 queries.
2 Correct 2 ms 300 KB Guessed the password with 154 queries.
3 Correct 1 ms 208 KB Guessed the password with 27 queries.
4 Correct 3 ms 208 KB Guessed the password with 103 queries.
5 Correct 1 ms 208 KB Guessed the password with 17 queries.
6 Correct 3 ms 300 KB Guessed the password with 133 queries.
7 Correct 120 ms 4264 KB Guessed the password with 3770 queries.
8 Correct 285 ms 12984 KB Guessed the password with 9261 queries.
9 Correct 344 ms 16544 KB Guessed the password with 9839 queries.
10 Correct 728 ms 37744 KB Guessed the password with 18313 queries.
11 Correct 1256 ms 94304 KB Guessed the password with 33171 queries.
12 Correct 1010 ms 25900 KB Guessed the password with 9059 queries.
13 Correct 1780 ms 140436 KB Guessed the password with 46117 queries.
14 Correct 1391 ms 54556 KB Guessed the password with 17880 queries.
15 Correct 1786 ms 140616 KB Guessed the password with 43506 queries.
16 Correct 1524 ms 52732 KB Guessed the password with 16258 queries.
17 Execution timed out 1702 ms 159000 KB Time limit exceeded (wall clock)
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Guessed the password with 86 queries.
2 Correct 2 ms 300 KB Guessed the password with 154 queries.
3 Correct 1 ms 208 KB Guessed the password with 27 queries.
4 Correct 3 ms 208 KB Guessed the password with 103 queries.
5 Correct 1 ms 208 KB Guessed the password with 17 queries.
6 Correct 3 ms 300 KB Guessed the password with 133 queries.
7 Correct 120 ms 4264 KB Guessed the password with 3770 queries.
8 Correct 285 ms 12984 KB Guessed the password with 9261 queries.
9 Correct 344 ms 16544 KB Guessed the password with 9839 queries.
10 Correct 728 ms 37744 KB Guessed the password with 18313 queries.
11 Correct 1256 ms 94304 KB Guessed the password with 33171 queries.
12 Correct 1010 ms 25900 KB Guessed the password with 9059 queries.
13 Correct 1780 ms 140436 KB Guessed the password with 46117 queries.
14 Correct 1391 ms 54556 KB Guessed the password with 17880 queries.
15 Correct 1786 ms 140616 KB Guessed the password with 43506 queries.
16 Correct 1524 ms 52732 KB Guessed the password with 16258 queries.
17 Execution timed out 1702 ms 159000 KB Time limit exceeded (wall clock)
18 Halted 0 ms 0 KB -