結果

問題 No.939 and or
ユーザー tonyu0
提出日時 2019-12-26 08:23:16
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 785 bytes
コンパイル時間 12,030 ms
コンパイル使用メモリ 392,100 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-02 12:33:48
合計ジャッジ時間 13,374 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let a: usize = itr.next().unwrap().parse().unwrap();
    let mut b: usize = itr.next().unwrap().parse().unwrap();

    // まずaのビットがbで全部立ってるか確認
    let mut i: usize = 0;
    while a >> i > 0 || b >> i > 0 {
        if a >> i & 1 == 1 && b >> i & 1 == 0 {
            println!("0");
            return;
        }
        i += 1;
    }
    b ^= a;
    if b == 0 {
        println!("1");
        return;
    }
    i = 0;
    let mut ans: u64 = 1;
    while b >> i > 0 {
        if b >> i & 1 == 1 {
            ans *= 2;
        }
        i += 1;
    }
    println!("{}", ans / 2);
}
0