結果

問題 No.1426 Got a Covered OR
ユーザー koba-e964koba-e964
提出日時 2021-10-06 09:37:44
言語 Rust
(1.77.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 2,410 bytes
コンパイル時間 937 ms
コンパイル使用メモリ 151,272 KB
実行使用メモリ 4,440 KB
最終ジャッジ日時 2023-09-30 08:39:00
合計ジャッジ時間 3,427 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 14 ms
4,376 KB
testcase_13 AC 22 ms
4,380 KB
testcase_14 AC 17 ms
4,376 KB
testcase_15 AC 15 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 16 ms
4,376 KB
testcase_19 AC 17 ms
4,376 KB
testcase_20 AC 7 ms
4,376 KB
testcase_21 AC 11 ms
4,380 KB
testcase_22 AC 39 ms
4,380 KB
testcase_23 AC 30 ms
4,388 KB
testcase_24 AC 16 ms
4,440 KB
testcase_25 AC 23 ms
4,380 KB
testcase_26 AC 23 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

const MOD: i64 = 1_000_000_007;

fn powmod(x: i64, mut e: i64) -> i64 {
    let mut sum = 1;
    let mut cur = x % MOD;
    while e > 0 {
        if e % 2 != 0 {
            sum = sum * cur % MOD;
        }
        cur = cur * cur % MOD;
        e /= 2;
    }
    sum
}

fn calc(x: u32, y: u32, len: usize) -> i64 {
    if y == 0 {
        let tmp = powmod(2, x as i64) - 1;
        return powmod(tmp, len as i64);
    }
    // \sum (-1)^i C(len, i) * 2^{x * (len - i)} * (2^{len - i} - 1)^y
    let mut comb = 1;
    let mut tot = 0;
    for i in 0..len + 1 {
        let row = powmod(2, (len - i) as i64) - 1;
        let tmp = comb * powmod(2, x as i64 * (len - i) as i64) % MOD
            * powmod(row, y as i64) % MOD;
        if i % 2 == 0 {
            tot = (tot + tmp) % MOD;
        } else {
            tot = (tot + MOD - tmp) % MOD;
        }
        comb = comb * (len - i) as i64 % MOD
            * powmod(i as i64 + 1, MOD - 2) % MOD;
    }
    tot
}

fn main() {
    input! {
        n: usize,
        b: [i64; n],
    }
    let mut c = vec![(0, 0)];
    for i in 0..n {
        if b[i] >= 0 {
            c.push((b[i], i + 1));
        }
    }
    let mut prod = 1;
    for i in 0..c.len() - 1 {
        let (x, y) = c[i];
        let (z, w) = c[i + 1];
        if (x & z) != x {
            println!("0");
            return;
        }
        prod = prod * calc(x.count_ones(), (x ^ z).count_ones(), w - y) % MOD;
    }
    println!("{}", prod);
}
0