結果

問題 No.1419 Power Moves
ユーザー koba-e964koba-e964
提出日時 2021-12-17 00:05:51
言語 Rust
(1.77.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 2,056 bytes
コンパイル時間 4,780 ms
コンパイル使用メモリ 147,548 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-12 00:06:39
合計ジャッジ時間 9,811 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,356 KB
testcase_02 AC 1 ms
4,356 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 104 ms
4,352 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 18 ms
4,348 KB
testcase_12 AC 110 ms
4,352 KB
testcase_13 AC 97 ms
4,352 KB
testcase_14 AC 128 ms
4,352 KB
testcase_15 AC 130 ms
4,348 KB
testcase_16 AC 129 ms
4,348 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 1 ms
4,352 KB
testcase_20 AC 130 ms
4,356 KB
testcase_21 AC 130 ms
4,348 KB
testcase_22 AC 132 ms
4,348 KB
testcase_23 AC 133 ms
4,352 KB
testcase_24 AC 133 ms
4,352 KB
testcase_25 AC 132 ms
4,356 KB
testcase_26 AC 131 ms
4,352 KB
testcase_27 AC 132 ms
4,352 KB
testcase_28 AC 132 ms
4,348 KB
testcase_29 AC 135 ms
4,356 KB
testcase_30 AC 130 ms
4,348 KB
testcase_31 AC 131 ms
4,352 KB
testcase_32 AC 131 ms
4,348 KB
testcase_33 AC 132 ms
4,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;

#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}

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 powmod(x: i64, mut e: i64, m: i64) -> i64 {
    let mut sum = 1;
    let mut cur = x % m;
    while e > 0 {
        if e % 2 != 0 {
            sum = sum * cur % m;
        }
        cur = cur * cur % m;
        e /= 2;
    }
    sum
}

const MOD: i64 = 1_000_000_007;

fn solve() {
    let n: usize = get();
    let k: i64 = get();
    let x = powmod(2, k, n as i64);
    let base = powmod(2, MOD - 1 - k, MOD);
    let x = (n + 1 - x as usize) % n;
    let m = if n % 2 == 0 {
        n / 2
    } else {
        n
    };
    let r = powmod(2, k, m as i64);
    let q = (powmod(2, k, MOD) + MOD - r) * powmod(m as i64, MOD - 2, MOD) % MOD;
    let mut ans = vec![0; n];
    for i in 0..m {
        if i < r as usize {
            ans[(x + 2 * i) % n] = (q + 1) * base % MOD;
        } else {
            ans[(x + 2 * i) % n] = q * base % MOD;
        }
    }
    for i in 0..n {
        println!("{}", ans[i]);
    }
}

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();
}
0