結果
| 問題 |
No.1419 Power Moves
|
| コンテスト | |
| ユーザー |
Strorkis
|
| 提出日時 | 2021-03-06 14:01:21 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 2,000 ms |
| コード長 | 4,224 bytes |
| コンパイル時間 | 23,410 ms |
| コンパイル使用メモリ | 389,764 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-08 12:39:05 |
| 合計ジャッジ時間 | 16,768 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
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);
}
Strorkis