結果
問題 | No.797 Noelちゃんとピラミッド |
ユーザー | Yukino DX. |
提出日時 | 2024-09-06 10:15:39 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 4,300 bytes |
コンパイル時間 | 11,525 ms |
コンパイル使用メモリ | 404,292 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-06 10:15:57 |
合計ジャッジ時間 | 14,787 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,820 KB |
testcase_02 | AC | 0 ms
6,816 KB |
testcase_03 | AC | 9 ms
6,944 KB |
testcase_04 | AC | 8 ms
6,940 KB |
testcase_05 | AC | 9 ms
6,940 KB |
testcase_06 | AC | 9 ms
6,940 KB |
testcase_07 | AC | 9 ms
6,940 KB |
testcase_08 | AC | 9 ms
6,944 KB |
testcase_09 | AC | 9 ms
6,940 KB |
testcase_10 | AC | 9 ms
6,940 KB |
testcase_11 | AC | 10 ms
6,944 KB |
testcase_12 | AC | 9 ms
6,940 KB |
testcase_13 | AC | 9 ms
6,944 KB |
testcase_14 | AC | 9 ms
6,944 KB |
testcase_15 | AC | 9 ms
6,944 KB |
testcase_16 | AC | 9 ms
6,944 KB |
testcase_17 | AC | 9 ms
6,940 KB |
testcase_18 | AC | 9 ms
6,940 KB |
testcase_19 | AC | 9 ms
6,940 KB |
testcase_20 | AC | 9 ms
6,944 KB |
testcase_21 | AC | 9 ms
6,944 KB |
testcase_22 | AC | 9 ms
6,940 KB |
testcase_23 | AC | 7 ms
6,940 KB |
testcase_24 | AC | 3 ms
6,944 KB |
testcase_25 | AC | 6 ms
6,944 KB |
testcase_26 | AC | 5 ms
6,940 KB |
testcase_27 | AC | 9 ms
6,944 KB |
testcase_28 | AC | 8 ms
6,944 KB |
testcase_29 | AC | 2 ms
6,940 KB |
testcase_30 | AC | 3 ms
6,944 KB |
testcase_31 | AC | 7 ms
6,944 KB |
testcase_32 | AC | 4 ms
6,940 KB |
testcase_33 | AC | 6 ms
6,940 KB |
testcase_34 | AC | 4 ms
6,940 KB |
testcase_35 | AC | 9 ms
6,944 KB |
testcase_36 | AC | 2 ms
6,940 KB |
testcase_37 | AC | 8 ms
6,940 KB |
testcase_38 | AC | 8 ms
6,940 KB |
testcase_39 | AC | 6 ms
6,944 KB |
testcase_40 | AC | 2 ms
6,944 KB |
testcase_41 | AC | 3 ms
6,944 KB |
testcase_42 | AC | 6 ms
6,940 KB |
testcase_43 | AC | 1 ms
6,940 KB |
testcase_44 | AC | 1 ms
6,940 KB |
testcase_45 | AC | 1 ms
6,944 KB |
testcase_46 | AC | 1 ms
6,944 KB |
testcase_47 | AC | 1 ms
6,944 KB |
testcase_48 | AC | 1 ms
6,944 KB |
testcase_49 | AC | 1 ms
6,944 KB |
testcase_50 | AC | 1 ms
6,944 KB |
testcase_51 | AC | 1 ms
6,940 KB |
testcase_52 | AC | 1 ms
6,940 KB |
testcase_53 | AC | 1 ms
6,940 KB |
testcase_54 | AC | 1 ms
6,944 KB |
testcase_55 | AC | 1 ms
6,940 KB |
testcase_56 | AC | 1 ms
6,940 KB |
testcase_57 | AC | 1 ms
6,944 KB |
testcase_58 | AC | 1 ms
6,944 KB |
testcase_59 | AC | 1 ms
6,944 KB |
testcase_60 | AC | 0 ms
6,940 KB |
testcase_61 | AC | 1 ms
6,940 KB |
testcase_62 | AC | 1 ms
6,944 KB |
ソースコード
use proconio::input; fn main() { input! { n:usize, a:[usize;n], } let comb = Combination::<MOD>::new(n - 1); let mut ans = ModInt::<MOD>::new(0); for i in 0..n { ans += ModInt::new(a[i]) * comb.comb(n - 1, i); } println!("{}", ans); } const MOD: usize = 1000000007; use combination::*; use modint::*; mod combination { use crate::modint::*; pub struct Combination<const MOD: usize> { fac: Vec<ModInt<MOD>>, finv: Vec<ModInt<MOD>>, } impl<const MOD: usize> Combination<MOD> { pub fn new(n: usize) -> Self { let mut fac = vec![ModInt::new(1); n + 1]; let mut inv = vec![ModInt::new(1); n + 1]; let mut finv = vec![ModInt::new(1); n + 1]; for i in 2..=n { fac[i] = fac[i - 1] * ModInt::<MOD>::new(i); inv[i] = -inv[MOD % i] * ModInt::<MOD>::new(MOD / i); finv[i] = finv[i - 1] * inv[i]; } Self { fac, finv } } pub fn comb(&self, n: usize, k: usize) -> ModInt<MOD> { if n < k { ModInt::new(0) } else { self.fac[n] * self.finv[n - k] * self.finv[k] } } } } mod modint { use std::fmt; use std::ops; #[derive(Copy, Clone, PartialEq, Eq)] pub struct ModInt<const MOD: usize> { pub val: usize, } impl<const MOD: usize> ModInt<MOD> { pub fn new(val: usize) -> Self { Self { val: val % MOD } } pub fn pow(mut self, mut e: usize) -> Self { let mut res = Self::new(1); while 0 < e { if e & 1 != 0 { res *= self; } self *= self; e >>= 1; } res } } impl<const MOD: usize> From<usize> for ModInt<MOD> { fn from(value: usize) -> Self { Self { val: value % MOD } } } impl<const MOD: usize> fmt::Display for ModInt<MOD> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.val) } } impl<const MOD: usize> fmt::Debug for ModInt<MOD> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.val) } } impl<const MOD: usize> ops::Neg for ModInt<MOD> { type Output = Self; fn neg(self) -> Self::Output { Self { val: (MOD - self.val) % MOD, } } } impl<const MOD: usize> ops::Add for ModInt<MOD> { type Output = Self; fn add(self, rhs: Self) -> Self::Output { Self { val: (self.val + rhs.val) % MOD, } } } impl<const MOD: usize> ops::AddAssign for ModInt<MOD> { fn add_assign(&mut self, rhs: Self) { *self = *self + rhs; } } impl<const MOD: usize> ops::Mul for ModInt<MOD> { type Output = Self; fn mul(self, rhs: Self) -> Self::Output { Self { val: self.val * rhs.val % MOD, } } } impl<const MOD: usize> ops::MulAssign for ModInt<MOD> { fn mul_assign(&mut self, rhs: Self) { *self = *self * rhs; } } impl<const MOD: usize> ops::Sub for ModInt<MOD> { type Output = Self; fn sub(mut self, rhs: Self) -> Self::Output { if self.val < rhs.val { self.val += MOD; } Self { val: (self.val - rhs.val) % MOD, } } } impl<const MOD: usize> ops::SubAssign for ModInt<MOD> { fn sub_assign(&mut self, rhs: Self) { if self.val < rhs.val { self.val += MOD; } *self = *self - rhs; } } impl<const MOD: usize> ops::Div for ModInt<MOD> { type Output = Self; fn div(self, rhs: Self) -> Self { assert!(rhs.val != 0); self * rhs.pow(MOD - 2) } } impl<const MOD: usize> ops::DivAssign for ModInt<MOD> { fn div_assign(&mut self, rhs: Self) { *self = *self / rhs } } }