結果

問題 No.2165 Let's Play Nim!
ユーザー akakimidori
提出日時 2022-12-16 00:09:27
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 207 ms / 2,000 ms
コード長 1,259 bytes
コンパイル時間 13,169 ms
コンパイル使用メモリ 390,524 KB
実行使用メモリ 25,488 KB
平均クエリ数 863.56
最終ジャッジ日時 2024-11-14 16:04:58
合計ジャッジ時間 33,874 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 32 TLE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let _n = read()[0];
    let find = |a: &[i64]| -> (usize, i64) {
        let xor = a.iter().fold(0, |s, a| s ^ *a);
        assert!(xor > 0);
        for (i, &a) in a.iter().enumerate() {
            for j in 1..=a {
                if xor ^ a ^ (a - j) == 0 {
                    return (i, j);
                }
            }
        }
        todo!()
    };
    let mut a = read();
    let xor = a.iter().fold(0, |s, a| s ^ *a);
    if xor > 0 {
        println!("1");
        let (x, k) = find(&a);
        a[x] -= k;
        println!("{} {}", x + 1, k);
        let res = read()[0];
        if res == -1 {
            return;
        }
    } else {
        println!("0");
    }
    loop {
        let (x, k) = {
            let a = read();
            (a[0] as usize - 1, a[1])
        };
        a[x] -= k;
        let res = read()[0];
        if res == -1 {
            break;
        }
        let (x, k) = find(&a);
        a[x] -= k;
        println!("{} {}", x + 1, k);
        let res = read()[0];
        if res == -1 {
            break;
        }
    }
}

fn read() -> Vec<i64> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().flat_map(|s| s.parse()).collect()
}
0