結果

問題 No.2768 Password Crack
ユーザー tobbie
提出日時 2024-07-17 21:31:53
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 698 bytes
コンパイル時間 1,624 ms
コンパイル使用メモリ 169,788 KB
実行使用メモリ 25,476 KB
平均クエリ数 773.20
最終ジャッジ日時 2024-07-17 21:31:59
合計ジャッジ時間 4,463 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i, n) for (int i = 0; i < (int)n; i++)

int main() {
  int N;
  cin >> N;
  string S = "";
  rep(i, N)
    S += 'z';
  cout << "? " << S << endl;
  int m;
  cin >> m;
  vector<int> a(N, 0);
  for (int i = 0; i < 25 && m < N; i++) {
    int pren = 0;
    rep(j, N) {
      if (a[j] > 0)
	continue;
      string T = S;
      T[j] = 'a' + i;
      cout << "? " << T << endl;
      int n;
      cin >> n;
      if (n < pren) {
	a[j] = 1;
      } else {
	if (n - m > 0) {
	  if (a[j] == 0) {
	    S[j] = 'a' + i;
	    a[j] = 1;
	    m++;
	  }
	}
	pren = n;
      }
      if (m == N)
	break;
    }
  }
  cout << "! " << S << endl;
  return 0;
}
0