Language: C++

// https://atcoder.jp/contests/agc044/tasks/agc044_d
#define CIN_ONLY
#define DECIMAL_DIGITS 10
#define STATIC_MOD 1e9 + 7

#ifdef BTK
/*<head>*/
#    include "Template.hpp"
/*</head>*/
#else
/*<body>*/
/*</body>*/
#endif

/**
 * 全文字の個数を128ずつ投げることで、全文字の個数を特定できる
 * 62クエリで各文字数を特定できる
 */
using V  = vector<int>;
using VV = vector<V>;

const string resource = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR"
                        "STUVWXYZaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";

int cnt[62];

namespace forlocal {
    string seq;
    int times = 0;
    void init() {
        auto rnd = XorShift32();
        // int n    = rnd.next_int() % 120 + 1;
        int n = 128;
        seq   = string(n, '-');
        for (int i : range(n)) {
            seq[i] = resource[rnd.next_int() % resource.size()];
        }
        cerr << n << endl;
        cerr << "A: " << join(seq, "") << endl;
    }
    int get(string q) {
        times++;
        VV dp(seq.size() + 1u, V(q.size() + 1, 256));
        dp[0][0] = 0;
        for (size_t i : range(seq.size() + 1)) {
            for (size_t j : range(q.size() + 1)) {
                if (i < seq.size()) {
                    // 削除
                    chmin(dp[i + 1][j], dp[i][j] + 1);
                }
                if (j < q.size()) {
                    // 挿入
                    chmin(dp[i][j + 1], dp[i][j] + 1);
                }
                if (i < seq.size() && j < q.size()) {
                    if (seq[i] == q[j]) {
                        chmin(dp[i + 1][j + 1], dp[i][j]);
                    }
                    else {
                        chmin(dp[i + 1][j + 1], dp[i][j] + 1);
                    }
                }
            }
        }
        cerr << "[" << times << "th query]" << endl;
        cerr << "A: " << join(seq, "") << endl;
        cerr << "Q: " << join(q, "") << endl;
        cerr << ">> " << dp.back().back() << endl;

        return dp.back().back();
    }
} // namespace forlocal

int len = 0;

int query(string q) {
#ifdef BTK
    int ans = forlocal::get(q);
#else
    cout << "? " << q << endl;
    cout.flush();
    int ans;
    cin >> ans;
    cout.flush();
#endif
    if (ans == 0) {
        cout << "! " << q << endl;
    }
    return ans;
}

void init() {
#ifdef BTK
    forlocal::init();
#endif
}

struct X {
    int l, r, num;
    X() {}
    X(int _l, int _r, int _num) {
        l   = _l;
        r   = _r;
        num = _num;
    }
};

string getInvalidString(int n) {
    string ret(n, '-');
    int min_i = distance(cnt, min_element(cnt, cnt + 62));
    string q(n, resource[(min_i + 1) % 62]);
    int def = n - query(q);
    for (int i : range(n)) {
        string s    = q;
        s[i]        = resource[min_i];
        int matched = n - query(s);
        if (matched > def) {
            ret[i] = q[i];
        }
        else {
            ret[i] = s[i];
        }
    }
    return ret;
}
int main() {
    init();
    /* write here */

    // 文字数特定 62クエリ
    for (int i : range(62)) {
        cnt[i] = 128 - query(string(128, resource[i]));
        len += cnt[i];
    }
    string result(len, '-');

    string invalid = getInvalidString(len);
    assert(query(invalid) == len);
    vector<int> ord(62);
    iota(ALL(ord), 0);
    sort(ALL(ord), [](int l, int r) { return cnt[l] > cnt[r]; });
    for (int i : range(61)) {
        stack<X> s;
        s.push(X(0, len, cnt[i]));
        while (s.size() > 0) {
            X cur = s.top();
            s.pop();
            if (cur.num == 0) continue;

            int rest = 0;
            for (int k : range(cur.l, cur.r)) {
                if (result[k] == '-') {
                    rest++;
                }
            }
            if (rest == cur.num) {
                for (int k : range(cur.l, cur.r)) {
                    if (result[k] == '-') {
                        result[k] = resource[i];
                    }
                }
                break;
            }

            int m    = (cur.l + cur.r) / 2;
            string q = invalid;
            for (int k : range(cur.l, m)) {
                q[k] = resource[i];
            }
            int v = len - query(q);
            s.push(X(cur.l, m, v));
            s.push(X(m, cur.r, cur.num - v));
        }
    }
    for (auto &c : result) {
        if (c == '-') {
            c = resource[ord[61]];
        }
    }
    query(result);
    return 0;
}

Compiler output:
a.cc:19:12: error: 'vector' does not name a type
   19 | using V  = vector<int>;
      |            ^~~~~~
a.cc:20:12: error: 'vector' does not name a type
   20 | using VV = vector<V>;
      |            ^~~~~~
a.cc:22:7: error: 'string' does not name a type
   22 | const string resource = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR"
      |       ^~~~~~
a.cc:28:5: error: 'string' does not name a type
   28 |     string seq;
      |     ^~~~~~
a.cc: In function 'void forlocal::init()':
a.cc:31:20: error: 'XorShift32' was not declared in this scope
   31 |         auto rnd = XorShift32();
      |                    ^~~~~~~~~~
a.cc:34:9: error: 'seq' was not declared in this scope
   34 |         seq   = string(n, '-');
      |         ^~~
a.cc:34:17: error: 'string' was not declared in this scope
   34 |         seq   = string(n, '-');
      |                 ^~~~~~
a.cc:35:22: error: 'range' was not declared in this scope
   35 |         for (int i : range(n)) {
      |                      ^~~~~
a.cc:36:22: error: 'resource' was not declared in this scope
   36 |             seq[i] = resource[rnd.next_int() % resource.size()];
      |                      ^~~~~~~~
a.cc:38:9: error: 'cerr' was not declared in this scope
   38 |         cerr << n << endl;
      |         ^~~~
a.cc:38:22: error: 'endl' was not declared in this scope
   38 |         cerr << n << endl;
      |                      ^~~~
a.cc:39:26: error: 'join' was not declared in this scope
   39 |         cerr << "A: " << join(seq, "") << endl;
      |                          ^~~~
a.cc: At global scope:
a.cc:41:13: error: 'string' was not declared in this scope
   41 |     int get(string q) {
      |             ^~~~~~
a.cc:76:11: error: 'string' was not declared in this scope
   76 | int query(string q) {
      |           ^~~~~~
a.cc:108:1: error: 'string' does not name a type
  108 | string getInvalidString(int n) {
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:131:18: error: 'range' was not declared in this scope
  131 |     for (int i : range(62)) {
      |                  ^~~~~
a.cc:132:42: error: 'resource' was not declared in this scope
  132 |         cnt[i] = 128 - query(string(128, resource[i]));
      |                                          ^~~~~~~~
a.cc:132:30: error: 'string' was not declared in this scope
  132 |         cnt[i] = 128 - query(string(128, resource[i]));
      |                              ^~~~~~
a.cc:132:54: error: 'query' cannot be used as a function
  132 |         cnt[i] = 128 - query(string(128, resource[i]));
      |                                                      ^
a.cc:135:5: error: 'string' was not declared in this scope
  135 |     string result(len, '-');
      |     ^~~~~~
a.cc:137:11: error: expected ';' before 'invalid'
  137 |     string invalid = getInvalidString(len);
      |           ^~~~~~~~
      |           ;
a.cc:138:18: error: 'invalid' was not declared in this scope
  138 |     assert(query(invalid) == len);
      |                  ^~~~~~~
a.cc:138:25: error: 'query' cannot be used as a function
  138 |     assert(query(invalid) == len);
      |                         ^
a.cc:138:5: error: 'assert' was not declared in this scope
  138 |     assert(query(invalid) == len);
      |     ^~~~~~
a.cc:1:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
  +++ |+#include <cassert>
    1 | // https://atcoder.jp/contests/agc044/tasks/agc044_d
a.cc:139:5: error: 'vector' was not declared in this scope
  139 |     vector<int> ord(62);
      |     ^~~~~~
a.cc:139:12: error: expected primary-expression before 'int'
  139 |     vector<int> ord(62);
      |            ^~~
a.cc:140:14: error: 'ord' was not declared in this scope
  140 |     iota(ALL(ord), 0);
      |              ^~~
a.cc:140:10: error: 'ALL' was not declared in this scope
  140 |     iota(ALL(ord), 0);
      |          ^~~
a.cc:140:5: error: 'iota' was not declared in this scope
  140 |     iota(ALL(ord), 0);
      |     ^~~~
a.cc:141:5: error: 'sort' was not declared in this scope; did you mean 'short'?
  141 |     sort(ALL(ord), [](int l, int r) { return cnt[l] > cnt[r]; });
      |     ^~~~
      |     short
a.cc:142:18: error: 'range' was not declared in this scope
  142 |     for (int i : range(61)) {
      |                  ^~~~~
a.cc:143:9: error: 'stack' was not declared in this scope
  143 |         stack<X> s;
      |         ^~~~~
a.cc:143:16: error: expected primary-expression before '>' token
  143 |         stack<X> s;
      |                ^
a.cc:143:18: error: 's' was not declared in this scope
  143 |         stack<X> s;
      |                  ^
a.cc:152:21: error: 'result' was not declared in this scope; did you mean 'rest'?
  152 |                 if (result[k] == '-') {
      |                     ^~~~~~
      |                     rest
a.cc:158:25: error: 'result' was not declared in this scope; did you mean 'rest'?
  158 |                     if (result[k] == '-') {
      |                         ^~~~~~
      |                         rest
a.cc:159:37: error: 'resource' was not declared in this scope
  159 |                         result[k] = resource[i];
      |                                     ^~~~~~~~
a.cc:166:19: error: expected ';' before 'q'
  166 |             string q = invalid;
      |                   ^~
      |                   ;
a.cc:168:17: error: 'q' was not declared in this scope
  168 |                 q[k] = resource[i];
      |                 ^
a.cc:168:24: error: 'resource' was not declared in this scope
  168 |                 q[k] = resource[i];
      |                        ^~~~~~~~
a.cc:170:33: error: 'q' was not declared in this scope
  170 |             int v = len - query(q);
      |                                 ^
a.cc:170:34: error: 'query' cannot be used as a function
  170 |             int v = len - query(q);
      |                                  ^
a.cc:175:20: error: 'result' was not declared in this scope
  175 |     for (auto &c : result) {
      |                    ^~~~~~
a.cc:177:17: error: 'resource' was not declared in this scope
  177 |             c = resource[ord[61]];
      |                 ^~~~~~~~
a.cc:180:11: error: 'result' was not declared in this scope
  180 |     query(result);
      |           ^~~~~~
a.cc:180:17: error: 'query' cannot be used as a function
  180 |     query(result);
      |                 ^