結果

問題 No.2768 Password Crack
ユーザー atcoder8
提出日時 2024-05-31 22:22:09
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 1,081 bytes
コンパイル時間 14,962 ms
コンパイル使用メモリ 388,464 KB
実行使用メモリ 25,488 KB
平均クエリ数 1785.17
最終ジャッジ日時 2024-12-20 23:58:39
合計ジャッジ時間 23,956 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other WA * 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