Code
#include <iostream>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define ll long long
#define db double
#define L(i, j, k) for (int i = (j); i <= (k); ++ i)
#define R(i, j, k) for (int i = (j); i >= (k); -- i)
#define mp(x, y) make_pair(x, y)
#define pii pair <int, int>
#define vi vector <int>
#define eb emplace_back
#define pb push_back
#define sz(v) ((int) v.size())
#define mem(f, x) memset(f, x, sizeof (f))
#define ACN(i, head, u) for (int i = head[u]; i; i = e[i].nxt)
using namespace std;
template <typename INT> void rd(INT &res) {
res = 0; bool f = 0; char ch = getchar();
while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar();
while (ch >= '0' && ch <= '9') res = (res << 1) + (res << 3) + (ch ^ 48), ch = getchar();
res = (f ? -res : res);
}
template <typename INT, typename ...Args>
void rd(INT &res, Args &..._res) { rd(res), rd(_res...); }
//xyy
string S;
const int N = 62, L = 128;
int cnt[N], len;
//myj
int ask(string s) { cout << "? " << s << endl; int x; cin >> x; return x; }
//zyj
string solve(int l, int r) {
if (l == r) {
string res = "";
L(i, 1, cnt[l]) res += S[l];
return res;
}
int mid = l + r >> 1;
string A = solve(l, mid), B = solve(mid + 1, r), res = "";
int i = 0, j = 0;
while (i < sz(A) || j < sz(B)) {
if (i == sz(A)) res += B[j ++];
else if (j == sz(B)) res += A[i ++];
else {
string t = res + A[i] + B.substr(j);
if (ask(t) + sz(t) == len) res += A[i ++];
else res += B[j ++];
}
}
return res;
}
signed main() {
// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
L(i, 0, 25) S += (char) i + 'a';
L(i, 0, 25) S += (char) i + 'A';
L(i, 0, 9) S += (char) i + '0';
L(i, 0, N - 1) {
string s;
L(j, 0, L - 1) s.pb(S[i]);
cnt[i] = L - ask(s), len += cnt[i];
}
cout << "! " << solve(0, N - 1) << endl;
return 0;
}
这是调试的代码:
#include <iostream>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define ll long long
#define db double
#define L(i, j, k) for (int i = (j); i <= (k); ++ i)
#define R(i, j, k) for (int i = (j); i >= (k); -- i)
#define mp(x, y) make_pair(x, y)
#define pii pair <int, int>
#define vi vector <int>
#define eb emplace_back
#define pb push_back
#define sz(v) ((int) v.size())
#define mem(f, x) memset(f, x, sizeof (f))
#define ACN(i, head, u) for (int i = head[u]; i; i = e[i].nxt)
using namespace std;
template <typename INT> void rd(INT &res) {
res = 0; bool f = 0; char ch = getchar();
while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar();
while (ch >= '0' && ch <= '9') res = (res << 1) + (res << 3) + (ch ^ 48), ch = getchar();
res = (f ? -res : res);
}
template <typename INT, typename ...Args>
void rd(INT &res, Args &..._res) { rd(res), rd(_res...); }
//xyy
string S;
string ss;
const int N = 62, L = 128;
int cnt[N], tot = 0;
//myj
//mt19937 rnd(time(0));
int dp[200][200], len;
//myj
//int random(int l, int r) { return rnd() % (r - l + 1) + l; }
//int ask(string s) { cout << "? " << s << endl; int x; cin >> x; return x; }
int ask(string t) {
++ tot;
// while (true) {
// char ch;
// cin >> ch;
// if (ch == '!') {
// string t;
// cin >> t;
// if (ss == t) {
//// cout << "T" << endl;
// return -1;
// } else {
// cout << "F" << endl;
// return 114514;
// }
// } else {
// string t;
// cin >> t;
L(i, 0, L) dp[0][i] = dp[i][0] = i;
L(i, 1, sz(ss))
L(j, 1, sz(t)) {
if (ss[i - 1] == t[j - 1])
dp[i][j] = dp[i - 1][j - 1];
else dp[i][j] = min(min(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]) + 1;
}
// cout << dp[sz(ss)][sz(t)] << endl;
return dp[sz(ss)][sz(t)];
// }
// }
} // 交互
//zyj
string solve(int l, int r) {
if (l == r) {
string res = "";
L(i, 1, cnt[l]) res += S[l];
return res;
}
int mid = l + r >> 1;
string A = solve(l, mid), B = solve(mid + 1, r), res = "";
int i = 0, j = 0;
while (i < sz(A) || j < sz(B)) {
if (i == sz(A)) res += B[j ++];
else if (j == sz(B)) res += A[i ++];
else {
string t = res + A[i] + B.substr(j);
if (ask(t) + sz(t) == len) res += A[i ++];
else res += B[j ++];
}
}
return res;
}
//xyy
//zyj
signed main() {
// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
L(i, 0, L - 1) {
int sb = random(0, 61);
if (sb < 26) ss.pb((char) sb + 'a');
else if (sb < 52) ss.pb((char) sb - 26 + 'A');
else ss.pb((char) sb - 52 + '0');
}
// 随机生成一个串
// ss = "Atcod3rIsGreat";
cout << ss << endl;
L(i, 0, 25) S += (char) i + 'a';
L(i, 0, 25) S += (char) i + 'A';
L(i, 0, 9) S += (char) i + '0';
L(i, 0, N - 1) {
string s;
L(j, 0, L - 1) s.pb(S[i]);
cnt[i] = L - ask(s), len += cnt[i];
}
// cout << "! " << solve(0, N - 1) << '\n';
cout << solve(0, N - 1) << '\n';
cout << tot << '\n'; // ask 的询问次数
return 0;
}