結果

問題 No.183 たのしい排他的論理和(EASY)
コンテスト
ユーザー elphe
提出日時 2026-02-09 16:05:29
言語 Rust
(1.93.0 + proconio + num + itertools)
結果
AC  
実行時間 141 ms / 5,000 ms
コード長 974 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,510 ms
コンパイル使用メモリ 200,636 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2026-02-09 16:05:33
合計ジャッジ時間 3,874 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

fn main() {
    let stdin = std::io::read_to_string(std::io::stdin().lock()).unwrap();
    let mut stdin = stdin.split_ascii_whitespace();

    let n: usize = stdin.next().unwrap().parse().unwrap();
    let a: Vec<u16> = (0..n)
        .map(|_| stdin.next().unwrap().parse().unwrap())
        .collect();

    use std::io::Write;
    std::io::stdout()
        .lock()
        .write_all(output(solve(a)).as_bytes())
        .unwrap();
}

fn solve(a: Vec<u16>) -> u16 {
    let mut ans = 1;
    let mut is_reachable = [false; 1 << 15];
    let mut stk = Vec::with_capacity(1_000_000);

    is_reachable[0] = true;
    stk.push(0);
    while let Some(cur) = stk.pop() {
        a.iter().for_each(|&a| {
            if !is_reachable[(cur ^ a) as usize] {
                is_reachable[(cur ^ a) as usize] = true;
                ans += 1;
                stk.push(cur ^ a);
            }
        });
    }
    ans
}

fn output(ans: u16) -> String {
    ans.to_string() + "\n"
}
0