Submission #709175

# Submission time Handle Problem Language Result Execution time Memory
709175 2023-03-13T07:15:15 Z Halogen Password (RMI18_password) C++14
0 / 100
76 ms 444 KB
#include <bits/stdc++.h>

using namespace std;

int query(string q);

string guess(int n, int s) {
    string ans = "";

    set<char> remaining;
    int amt[s + 5];
    int cnt = 0;
    for (char i = 0; i < s; i++) {
        string g(n, i + 'a');
        amt[i] = query(g);
        cnt += amt[i];

        if (amt[i] > 0) remaining.insert(i);
        if (cnt == n) break;
        if (amt[i] == n) return g;
    }

    for (int k = 0; k < n; k++) {
        char cur = 0;
        for (char i : remaining) {
            string g(amt[cur], 'a' + i);
            g += ('a' + i);
            g += ans;
            int res = query(g);
            if (res == amt[cur]) continue;
            cur = i;
        }

        ans = string(1, 'a' + cur) + ans;
        amt[cur]--;

        if (amt[cur] == 0) remaining.erase(cur);
        if (remaining.size() == 1) {
            cur = *remaining.begin();
            string g(amt[cur], 'a' + cur);
            return g + ans;
        }
    }

    return ans;
}

Compilation message

password.cpp: In function 'std::string guess(int, int)':
password.cpp:15:13: warning: array subscript has type 'char' [-Wchar-subscripts]
   15 |         amt[i] = query(g);
      |             ^
password.cpp:16:20: warning: array subscript has type 'char' [-Wchar-subscripts]
   16 |         cnt += amt[i];
      |                    ^
password.cpp:18:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   18 |         if (amt[i] > 0) remaining.insert(i);
      |                 ^
password.cpp:20:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   20 |         if (amt[i] == n) return g;
      |                 ^
password.cpp:26:26: warning: array subscript has type 'char' [-Wchar-subscripts]
   26 |             string g(amt[cur], 'a' + i);
      |                          ^~~
password.cpp:30:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   30 |             if (res == amt[cur]) continue;
      |                            ^~~
password.cpp:35:13: warning: array subscript has type 'char' [-Wchar-subscripts]
   35 |         amt[cur]--;
      |             ^~~
password.cpp:37:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   37 |         if (amt[cur] == 0) remaining.erase(cur);
      |                 ^~~
password.cpp:40:26: warning: array subscript has type 'char' [-Wchar-subscripts]
   40 |             string g(amt[cur], 'a' + cur);
      |                          ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 208 KB Returned early from guess() after 135 queries.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 208 KB Returned early from guess() after 55 queries.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 76 ms 444 KB Returned early from guess() after 8207 queries.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 208 KB Returned early from guess() after 135 queries.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 208 KB Returned early from guess() after 135 queries.
2 Halted 0 ms 0 KB -