結果

問題 No.2768 Password Crack
ユーザー ortogawa
提出日時 2025-07-25 06:58:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 617 bytes
コンパイル時間 2,221 ms
コンパイル使用メモリ 195,524 KB
実行使用メモリ 26,240 KB
平均クエリ数 885.00
最終ジャッジ日時 2025-07-25 06:58:13
合計ジャッジ時間 6,584 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int query(string s) {
	cout << "? " << s << endl;
	int ans; cin >> ans;
	return ans;
}

int main() {
	int n; cin >> n;

	int cnt = query(string(n, 'a'));

	string ans;
	for (int i = 0; i < n; i++) {
		string t(n, 'a');
		t[i] = 'b';
		int ncnt = query(t);

		if (ncnt > cnt) {
			ans += 'b';
		} else if (ncnt < cnt) {
			ans += 'a';
		} else {
			bool found = false;
			for (char x = 'c'; x < 'z'; x++) {
				t[i] = x;
				if (query(t) > cnt) {
					ans += x;
					found = true;
					break;
				}
			}
			if (!found) ans += 'z';
		}
	}

	cout << "! " << ans << endl;
}
0