Submission #709356

# Submission time Handle Problem Language Result Execution time Memory
709356 2023-03-13T13:16:49 Z maomao90 Password (RMI18_password) C++17
10 / 100
9 ms 552 KB
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 5005;

int query(string str);

int occ[30];

string dnc(int l, int r) {
    if (l == r) {
        return string(occ[l], 'a' + l);
    }
    int m = l + r >> 1;
    string sl = dnc(l, m), sr = dnc(m + 1, r);
    string str = sl;
    int ptr = 0;
    REP (i, 0, SZ(sr)) {
        str.insert(ptr, 1, sr[i]);
        while (ptr <= SZ(sr) + i && query(str) != SZ(str)) {
            str.erase(ptr, 1);
            ptr++;
            str.insert(ptr, 1, sr[i]);
        }
        ptr++;
    }
    return str;
}

string guess(int n, int s) {
    REP (c, 0, s) {
        string str(n, 'a' + c);
        occ[c] = query(str);
    }
    string ans = dnc(0, s - 1);
    return ans;
}

Compilation message

password.cpp: In function 'std::string dnc(int, int)':
password.cpp:46:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |     int m = l + r >> 1;
      |             ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Guessed the password with 66 queries.
2 Correct 1 ms 208 KB Guessed the password with 107 queries.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Guessed the password with 48 queries.
2 Incorrect 1 ms 208 KB Returned early from guess() after 30 queries.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 552 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Guessed the password with 66 queries.
2 Correct 1 ms 208 KB Guessed the password with 107 queries.
3 Correct 1 ms 208 KB Guessed the password with 48 queries.
4 Incorrect 1 ms 208 KB Returned early from guess() after 30 queries.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Guessed the password with 66 queries.
2 Correct 1 ms 208 KB Guessed the password with 107 queries.
3 Correct 1 ms 208 KB Guessed the password with 48 queries.
4 Incorrect 1 ms 208 KB Returned early from guess() after 30 queries.
5 Halted 0 ms 0 KB -