結果
| 問題 | No.1419 Power Moves |
| コンテスト | |
| ユーザー |
Strorkis
|
| 提出日時 | 2021-03-06 12:58:17 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,666 bytes |
| コンパイル時間 | 23,240 ms |
| コンパイル使用メモリ | 401,328 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-08 10:06:43 |
| 合計ジャッジ時間 | 17,469 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 21 |
ソースコード
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);
}
Strorkis