結果
問題 | No.1259 スイッチ |
ユーザー | fukafukatani |
提出日時 | 2020-10-17 15:43:50 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,130 bytes |
コンパイル時間 | 13,809 ms |
コンパイル使用メモリ | 390,936 KB |
実行使用メモリ | 17,644 KB |
最終ジャッジ日時 | 2024-07-21 02:43:38 |
合計ジャッジ時間 | 24,209 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
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 | WA | - |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 158 ms
11,176 KB |
testcase_11 | AC | 236 ms
16,512 KB |
testcase_12 | AC | 146 ms
10,700 KB |
testcase_13 | AC | 87 ms
7,092 KB |
testcase_14 | AC | 122 ms
9,372 KB |
testcase_15 | AC | 83 ms
6,912 KB |
testcase_16 | AC | 201 ms
13,952 KB |
testcase_17 | AC | 120 ms
9,088 KB |
testcase_18 | AC | 222 ms
15,488 KB |
testcase_19 | AC | 221 ms
15,500 KB |
testcase_20 | AC | 156 ms
11,320 KB |
testcase_21 | AC | 255 ms
16,840 KB |
testcase_22 | AC | 76 ms
6,400 KB |
testcase_23 | AC | 219 ms
15,232 KB |
testcase_24 | AC | 165 ms
12,032 KB |
testcase_25 | AC | 156 ms
11,648 KB |
testcase_26 | AC | 260 ms
17,024 KB |
testcase_27 | AC | 197 ms
14,208 KB |
testcase_28 | AC | 158 ms
11,776 KB |
testcase_29 | AC | 198 ms
14,252 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | AC | 137 ms
10,364 KB |
testcase_51 | AC | 73 ms
6,400 KB |
testcase_52 | AC | 237 ms
16,448 KB |
testcase_53 | AC | 104 ms
8,252 KB |
testcase_54 | AC | 231 ms
16,384 KB |
testcase_55 | AC | 70 ms
6,144 KB |
testcase_56 | AC | 117 ms
9,076 KB |
testcase_57 | AC | 223 ms
15,232 KB |
testcase_58 | AC | 163 ms
10,988 KB |
testcase_59 | AC | 180 ms
13,128 KB |
testcase_60 | AC | 252 ms
17,644 KB |
コンパイルメッセージ
warning: associated function `set_modulus` is never used --> src/main.rs:57:8 | 56 | impl Modulo { | ----------- associated function in this implementation 57 | fn set_modulus(m: i64) { | ^^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default
ソースコード
#![allow(unused_imports)] use std::cmp::*; use std::collections::*; use std::io::Write; use std::ops::Bound::*; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let v = read_vec::<i64>(); let (n, k, m) = (v[0], v[1], v[2] as usize); let mut fact = vec![Modulo(1); n as usize + 1]; for i in 1..n { fact[i as usize] = fact[i as usize - 1] * i; } let fact_inv = fact.iter().map(|&x| x.inv()).collect::<Vec<_>>(); let mut ans = Modulo(0i64); for yaku in 1..n + 1 { if k % yaku == 0 { ans += fact[n as usize - 1] * fact_inv[(n - yaku) as usize] * Modulo(n).pow(n - yaku); } } if m == 1 { println!("{}", ans); } ans = (Modulo(n).pow(n) - ans) * Modulo(n - 1).inv(); println!("{}", ans); } fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() } #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] struct Modulo(i64); static mut MODULUS: i64 = 1000_000_000 + 7; impl Modulo { fn set_modulus(m: i64) { unsafe { MODULUS = m; } } fn get_modulus() -> i64 { unsafe { MODULUS } } fn new(x: i64) -> Modulo { let m = Modulo::get_modulus(); if x < 0 { Modulo(x % m + m) } else if x < m { Modulo(x) } else { Modulo(x % m) } } fn pow(self, p: i64) -> Modulo { if p == 0 { Modulo(1) } else { let mut t = self.pow(p / 2); t *= t; if p & 1 == 1 { t *= self; } t } } fn inv(self) -> Modulo { self.pow(Modulo::get_modulus() - 2) } } impl std::fmt::Display for Modulo { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { self.0.fmt(f) } } impl std::ops::AddAssign for Modulo { fn add_assign(&mut self, other: Modulo) { let m = Modulo::get_modulus(); self.0 += other.0; if self.0 >= m { self.0 -= m; } } } impl std::ops::MulAssign for Modulo { fn mul_assign(&mut self, other: Modulo) { let m = Modulo::get_modulus(); self.0 *= other.0; self.0 %= m; } } impl std::ops::SubAssign for Modulo { fn sub_assign(&mut self, other: Modulo) { let m = Modulo::get_modulus(); self.0 += m - other.0; if self.0 >= m { self.0 -= m; } } } macro_rules! impl_modulo_ops { ($imp:ident, $method:ident, $assign_imp:ident, $assign_method:ident) => { impl<'a> std::ops::$assign_imp<&'a Modulo> for Modulo { fn $assign_method(&mut self, other: &'a Modulo) { std::ops::$assign_imp::$assign_method(self, *other); } } impl std::ops::$imp for Modulo { type Output = Modulo; fn $method(self, other: Modulo) -> Modulo { let mut x = self; std::ops::$assign_imp::$assign_method(&mut x, other); x } } impl<'a> std::ops::$imp<Modulo> for &'a Modulo { type Output = Modulo; fn $method(self, other: Modulo) -> Modulo { std::ops::$imp::$method(*self, other) } } impl<'a> std::ops::$imp<&'a Modulo> for Modulo { type Output = Modulo; fn $method(self, other: &'a Modulo) -> Modulo { std::ops::$imp::$method(self, *other) } } impl<'a, 'b> std::ops::$imp<&'b Modulo> for &'a Modulo { type Output = Modulo; fn $method(self, other: &'b Modulo) -> Modulo { std::ops::$imp::$method(*self, *other) } } impl std::ops::$assign_imp<i64> for Modulo { fn $assign_method(&mut self, other: i64) { std::ops::$assign_imp::$assign_method(self, Modulo::new(other)); } } impl<'a> std::ops::$assign_imp<&'a i64> for Modulo { fn $assign_method(&mut self, other: &'a i64) { std::ops::$assign_imp::$assign_method(self, *other); } } impl std::ops::$imp<i64> for Modulo { type Output = Modulo; fn $method(self, other: i64) -> Modulo { let mut x = self; std::ops::$assign_imp::$assign_method(&mut x, other); x } } impl<'a> std::ops::$imp<&'a i64> for Modulo { type Output = Modulo; fn $method(self, other: &'a i64) -> Modulo { std::ops::$imp::$method(self, *other) } } impl<'a> std::ops::$imp<i64> for &'a Modulo { type Output = Modulo; fn $method(self, other: i64) -> Modulo { std::ops::$imp::$method(*self, other) } } impl<'a, 'b> std::ops::$imp<&'b i64> for &'a Modulo { type Output = Modulo; fn $method(self, other: &'b i64) -> Modulo { std::ops::$imp::$method(*self, *other) } } }; } impl_modulo_ops!(Add, add, AddAssign, add_assign); impl_modulo_ops!(Mul, mul, MulAssign, mul_assign); impl_modulo_ops!(Sub, sub, SubAssign, sub_assign); use std::iter::Sum; impl Sum for Modulo { fn sum<I>(iter: I) -> Self where I: Iterator<Item = Modulo>, { iter.fold(Modulo(0), |a, b| a + b) } } impl<'a> Sum<&'a Modulo> for Modulo { fn sum<I>(iter: I) -> Self where I: Iterator<Item = &'a Self>, { iter.fold(Modulo(0), |a, b| a + b) } }