結果

問題 No.1419 Power Moves
ユーザー StrorkisStrorkis
提出日時 2021-03-06 12:58:17
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 3,666 bytes
コンパイル時間 1,009 ms
コンパイル使用メモリ 163,328 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 01:30:04
合計ジャッジ時間 3,196 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 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 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 22 ms
5,376 KB
testcase_15 AC 22 ms
5,376 KB
testcase_16 AC 22 ms
5,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
5,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod mod_int {
    pub trait ModInt {
        fn mod_safety_with(self, m: Self) -> Self;
        fn mod_add(self, other: Self) -> Self;
        fn mod_sub(self, other: Self) -> Self;
        fn mod_mul(self, other: 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_safety_with(mut self, m: Self) -> Self {
                    self %= m;
                    if self < 0 {
                        self + m
                    } else {
                        self
                    }
                }

                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_sub(self, other: Self) -> Self {
                    assert!(self < $m);
                    assert!(other < $m);
                    if self < other {
                        self + $m - other
                    } else {
                        self + other
                    }
                }
            
                fn mod_mul(self, other: Self) -> Self {
                    assert!(self < $m);
                    assert!(other < $m);
                    self * other % $m
                }
            
                fn mod_pow(mut self, mut exp: Self) -> Self {
                    assert!(self < $m);
                    let mut acc = 1;
                    while exp > 0 {
                        if exp & 1 == 1 {
                            acc = acc.mod_mul(self);
                        }
                        self = self.mod_mul(self);
                        exp /= 2;
                    }
                    acc
                }

                fn mod_inv(self) -> Self {
                    assert!(self < $m);
                    self.mod_pow($m - 2)
                }
            }                
        };
    }
    
    impl_mod_int!(i64, 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!((i64, i64));

    let p = 2i64.mod_pow(k - 1);
    let q = p / n;
    let r = p % n;

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

    for ans in ans {
        println!("{}", ans.mod_mul(p.mod_mul(2).mod_inv()));
    }
}

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