結果

問題 No.822 Bitwise AND
ユーザー koba-e964koba-e964
提出日時 2021-09-18 14:07:03
言語 Rust
(1.77.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,071 bytes
コンパイル時間 3,558 ms
コンパイル使用メモリ 135,416 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-13 00:50:07
合計ジャッジ時間 1,566 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 12 ms
4,380 KB
testcase_05 AC 9 ms
4,376 KB
testcase_06 AC 16 ms
4,376 KB
testcase_07 AC 12 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 7 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn get_word() -> String {
    let stdin = std::io::stdin();
    let mut stdin=stdin.lock();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn main() {
    let n: i32 = get();
    let k: i32 = get();
    let mut p = 1;
    while p <= n {
        p *= 2;
    }
    let mut ans = 0;
    for j in 0..k + 1 {
        for i in n..p {
            if (i & (i + j)) == n {
                ans += 1;
                if i + j >= p {
                    println!("INF");
                    return;
                }
            }
        }
    }
    println!("{}", ans);
}
0