結果

問題 No.2768 Password Crack
ユーザー atcoder8
提出日時 2024-05-31 22:22:29
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 1,083 bytes
コンパイル時間 18,339 ms
コンパイル使用メモリ 384,272 KB
実行使用メモリ 25,488 KB
平均クエリ数 1785.17
最終ジャッジ日時 2024-12-21 00:00:08
合計ジャッジ時間 21,297 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Write;

fn main() {
    let n = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse::<usize>().unwrap()
    };

    let mut t = vec!['a'; n];
    for i in 0..n {
        let scores = ('a'..'z')
            .map(|c| {
                t[i] = c;
                let ask = t.iter().collect::<String>();
                println!("? {}", ask);
                std::io::stdout().flush().unwrap();
                let score = {
                    let mut line = String::new();
                    std::io::stdin().read_line(&mut line).unwrap();
                    line.trim().parse::<usize>().unwrap()
                };

                score
            })
            .collect::<Vec<usize>>();

        if scores.iter().all(|&score| score == scores[0]) {
            t[i] = 'z';
        } else {
            let pos = (0..25).max_by_key(|&pos| scores[pos]).unwrap();
            t[i] = (b'a' + pos as u8) as char
        }
    }

    let ans = t.iter().collect::<String>();
    println!("! {}", ans);
}
0