結果

問題 No.985 Hadamard
ユーザー koba-e964koba-e964
提出日時 2021-12-11 14:46:26
言語 Rust
(1.77.0)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 2,335 bytes
コンパイル時間 4,708 ms
コンパイル使用メモリ 157,596 KB
実行使用メモリ 7,124 KB
最終ジャッジ日時 2023-09-27 02:17:11
合計ジャッジ時間 7,767 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 131 ms
7,100 KB
testcase_05 AC 66 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 66 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 127 ms
7,120 KB
testcase_14 AC 128 ms
7,100 KB
testcase_15 AC 126 ms
7,040 KB
testcase_16 AC 126 ms
6,964 KB
testcase_17 AC 127 ms
7,116 KB
testcase_18 AC 130 ms
7,052 KB
testcase_19 AC 131 ms
7,052 KB
testcase_20 AC 131 ms
6,984 KB
testcase_21 AC 129 ms
7,056 KB
testcase_22 AC 130 ms
7,068 KB
testcase_23 AC 110 ms
7,060 KB
testcase_24 AC 110 ms
7,044 KB
testcase_25 AC 109 ms
7,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::*;
// 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),* )) => { ($(read_value!($next, $t)),*) };
    ($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"));
}

trait Change { fn chmax(&mut self, x: Self); fn chmin(&mut self, x: Self); }
impl<T: PartialOrd> Change for T {
    fn chmax(&mut self, x: T) { if *self < x { *self = x; } }
    fn chmin(&mut self, x: T) { if *self > x { *self = x; } }
}

const MOD: i64 = 998_244_353;

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

fn solve() {
    input! {
        n: usize,
        c: [i64; 1 << n],
        lr: [(i64, i64); 1 << n],
    }
    let mut c = c;
    for i in 0..n {
        for bits in 0..1 << n {
            if (bits & 1 << i) != 0 { continue; }
            let x = c[bits];
            let y = c[bits | 1 << i];
            c[bits] = x + y;
            c[bits | 1 << i] = x - y;
        }
    }
    let mut tot = 0;
    for i in 0..1 << n {
        let (l, r) = lr[i];
        let t = (c[i] % MOD + MOD) % MOD;
        if c[i] > 0 {
            tot += (r + MOD) * t % MOD;
        } else {
            tot += (l + MOD) * t % MOD;
        }
    }
    tot %= MOD;
    let inv2 = (MOD + 1) / 2;
    for _ in 0..n {
        tot = tot * inv2 % MOD;
    }
    println!("{}", tot);
}
0