結果

問題 No.1419 Power Moves
ユーザー StrorkisStrorkis
提出日時 2021-03-06 14:01:21
言語 Rust
(1.77.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 4,224 bytes
コンパイル時間 4,288 ms
コンパイル使用メモリ 158,720 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 03:08:39
合計ジャッジ時間 6,140 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 0 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 6 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 6 ms
5,376 KB
testcase_14 AC 6 ms
5,376 KB
testcase_15 AC 6 ms
5,376 KB
testcase_16 AC 6 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 0 ms
5,376 KB
testcase_20 AC 7 ms
5,376 KB
testcase_21 AC 7 ms
5,376 KB
testcase_22 AC 7 ms
5,376 KB
testcase_23 AC 7 ms
5,376 KB
testcase_24 AC 7 ms
5,376 KB
testcase_25 AC 7 ms
5,376 KB
testcase_26 AC 7 ms
5,376 KB
testcase_27 AC 7 ms
5,376 KB
testcase_28 AC 6 ms
5,376 KB
testcase_29 AC 7 ms
5,376 KB
testcase_30 AC 7 ms
5,376 KB
testcase_31 AC 7 ms
5,376 KB
testcase_32 AC 7 ms
5,376 KB
testcase_33 AC 6 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod mod_int {
    pub trait ModInt {
        fn mod_add(self, other: Self) -> Self;
        fn mod_add_assign(&mut self, other: Self);
        fn mod_sub_with(self, other: Self, m: Self) -> Self;
        fn mod_sub(self, other: Self) -> Self;
        fn mod_mul_with(self, other: Self, m: Self) -> Self;
        fn mod_mul(self, other: Self) -> Self;
        fn mod_pow_with(self, exp: Self, m: Self) -> Self;
        fn mod_pow(self, exp: Self) -> Self;
        fn mod_inv(self) -> Self;
    }

    macro_rules! impl_mod_int {
        ($t:ty, $m:expr) => {
            impl ModInt for $t {
                fn mod_add(self, other: Self) -> Self {
                    assert!(self < $m);
                    assert!(other < $m);
                    let result = self + other;
                    if result < $m {
                        result
                    } else {
                        result - $m
                    }
                }

                fn mod_add_assign(&mut self, other: Self) {
                    *self = (*self).mod_add(other);
                }

                fn mod_sub_with(self, other: Self, m: Self) -> Self {
                    assert!(self < m);
                    assert!(other < m);
                    if self < other {
                        self + m - other
                    } else {
                        self - other
                    }
                }
            
                fn mod_sub(self, other: Self) -> Self {
                    self.mod_sub_with(other, $m)
                }
            
                fn mod_mul_with(self, other: Self, m: Self) -> Self {
                    assert!(self < m);
                    assert!(other < m);
                    self * other % m
                }

                fn mod_mul(self, other: Self) -> Self {
                    self.mod_mul_with(other, $m)
                }
            
                fn mod_pow_with(mut self, mut exp: Self, m: Self) -> Self {
                    assert!(self < m);
                    let mut acc = 1;
                    while exp > 0 {
                        if exp & 1 == 1 {
                            acc = acc.mod_mul_with(self, m);
                        }
                        self = self.mod_mul_with(self, m);
                        exp /= 2;
                    }
                    acc
                }

                fn mod_pow(self, exp: Self) -> Self {
                    self.mod_pow_with(exp, $m)
                }

                fn mod_inv(self) -> Self {
                    assert!(self < $m);
                    self.mod_pow($m - 2)
                }
            }                
        };
    }
    
    impl_mod_int!(u64, 1_000_000_007);
}

use mod_int::ModInt;

fn run<'a, F: FnMut() -> &'a str, W: std::io::Write>(scan: &mut F, writer: &mut W) {
    macro_rules! scan {
        ([$t:tt; $n:expr]) => ((0..$n).map(|_| scan!($t)).collect::<Vec<_>>());
        (($($t:tt),*)) => (($(scan!($t)),*));
        (Usize1) => (scan!(usize) - 1);
        (Bytes) => (scan().as_bytes().to_vec());
        ($t:ty) => (scan().parse::<$t>().unwrap());
    }
    macro_rules! println {
        ($($arg:tt)*) => (writeln!(writer, $($arg)*).ok());
    }

    let (n, k) = scan!((u64, u64));

    let r = 2u64.mod_pow_with(k - 1, n);
    let q = 2u64.mod_pow(k - 1).mod_sub(r).mod_mul(n.mod_inv());

    let mut ans = vec![0; n as usize];
    for i in 0..n {
        ans[((2 * i + 1) % n) as usize].mod_add_assign(q);
    }
    for i in 0..r {
        ans[((2 * i + 1) % n) as usize].mod_add_assign(1);
    }

    let tmp = ans.clone();
    for i in 0..n {
        ans[0u64.mod_sub_with(i, n) as usize].mod_add_assign(tmp[i as usize]);
    }

    let d = 2u64.mod_inv().mod_pow(k);
    for ans in ans {
        println!("{}", ans.mod_mul(d));
    }
}

fn main() {
    let ref mut buf = Vec::new();
    std::io::Read::read_to_end(&mut std::io::stdin(), buf).ok();
    let mut scanner = unsafe {
        std::str::from_utf8_unchecked(buf).split_ascii_whitespace()
    };
    let ref mut scan = || scanner.next().unwrap();

    let stdout = std::io::stdout();
    let ref mut writer = std::io::BufWriter::new(stdout.lock());

    run(scan, writer);
}
0