Submission #1162618

#TimeUsernameProblemLanguageResultExecution timeMemory
1162618cnn008Password (RMI18_password)C11
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

int query(string p);

string guess(int n, int s) {
    string ans;
    vector<int> cnt(s, 0);
    
    for (int i = 0; i < s; i++) {
        char c = char('a' + i);
        string cur;
        
        while ((int)cur.size() < n) {
            cur.push_back(c);
            if (query(cur) != (int)cur.size()) {
                cur.pop_back();
                break;
            }
        }
        
        cnt[i] = (int)cur.size();
    }

    int st = -1;
    for (int i = 0; i < s; i++) {
        if (cnt[i]) {
            char c = char(i + 'a');
            for (int j = 0; j < cnt[i]; j++) ans.push_back(c);
            st = i;
            break;
        }
    }

    // Convert the lambda function to a normal function
    struct Checker {
        int (*query)(string);
        string ans;

        bool check(char c, int l) {
            string t;
            t.push_back(c);
            
            for (int i = 0; i < (int)ans.size() - 1 - l + 1; i++) 
                if (ans[i] == c) t.push_back(c);
            
            for (int i = (int)ans.size() - 1 - l + 1; i < (int)ans.size(); i++) 
                t.push_back(ans[i]);

            return (query(t) == (int)t.size());
        }
    } ck = {query, ans}; // Assign function pointer

    for (int i = st + 1; i < s; i++) {
        for (int j = 0; j < cnt[i]; j++) {
            char c = char('a' + i);
            int l = 1, r = (int)ans.size(), cc = 0;

            while (l <= r) {
                int mid = (l + r) >> 1;
                if (ck.check(c, mid)) {
                    cc = mid;
                    l = mid + 1;
                } else {
                    r = mid - 1;
                }
            }

            string _ans;
            for (int i = (int)ans.size() - 1; i >= (int)ans.size() - 1 - cc + 1; i--) 
                _ans.push_back(ans[i]);

            _ans.push_back(c);

            for (int i = (int)ans.size() - 1 - cc + 1 - 1; i >= 0; i--) 
                _ans.push_back(ans[i]);

            reverse(_ans.begin(), _ans.end());
            ans.swap(_ans);
        }
    }

    assert((int)ans.size() == n);
    return ans;
}

Compilation message (stderr)

password.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.