結果
問題 | No.802 だいたい等差数列 |
ユーザー | akakimidori |
提出日時 | 2019-08-29 10:43:46 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 24 ms / 2,000 ms |
コード長 | 4,992 bytes |
コンパイル時間 | 9,737 ms |
コンパイル使用メモリ | 402,976 KB |
実行使用メモリ | 17,172 KB |
最終ジャッジ日時 | 2024-11-17 16:49:36 |
合計ジャッジ時間 | 11,124 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,820 KB |
testcase_01 | AC | 0 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,820 KB |
testcase_03 | AC | 1 ms
6,820 KB |
testcase_04 | AC | 0 ms
6,820 KB |
testcase_05 | AC | 1 ms
6,816 KB |
testcase_06 | AC | 1 ms
6,820 KB |
testcase_07 | AC | 1 ms
6,820 KB |
testcase_08 | AC | 0 ms
6,820 KB |
testcase_09 | AC | 1 ms
6,820 KB |
testcase_10 | AC | 18 ms
13,624 KB |
testcase_11 | AC | 21 ms
16,896 KB |
testcase_12 | AC | 11 ms
8,576 KB |
testcase_13 | AC | 19 ms
16,436 KB |
testcase_14 | AC | 15 ms
12,348 KB |
testcase_15 | AC | 10 ms
7,424 KB |
testcase_16 | AC | 15 ms
12,944 KB |
testcase_17 | AC | 1 ms
6,816 KB |
testcase_18 | AC | 1 ms
6,816 KB |
testcase_19 | AC | 12 ms
10,052 KB |
testcase_20 | AC | 18 ms
13,624 KB |
testcase_21 | AC | 23 ms
16,996 KB |
testcase_22 | AC | 20 ms
17,100 KB |
testcase_23 | AC | 7 ms
6,816 KB |
testcase_24 | AC | 1 ms
6,820 KB |
testcase_25 | AC | 0 ms
6,820 KB |
testcase_26 | AC | 5 ms
6,816 KB |
testcase_27 | AC | 4 ms
6,816 KB |
testcase_28 | AC | 12 ms
8,832 KB |
testcase_29 | AC | 24 ms
17,172 KB |
testcase_30 | AC | 1 ms
6,820 KB |
testcase_31 | AC | 1 ms
6,816 KB |
testcase_32 | AC | 0 ms
6,820 KB |
testcase_33 | AC | 7 ms
6,820 KB |
ソースコード
// ---------- begin ModInt ---------- //https://github.com/kenkoooo/competitive-programming-rs/blob/master/src/math/mod_int.rs //を参考にしています #[allow(dead_code)] mod modint { pub const MOD: u32 = 1_000_000_007; use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}; #[derive(Clone, Copy)] pub struct ModInt<T: Copy + Clone>(pub T); type Num = u32; impl Add<ModInt<Num>> for ModInt<Num> { type Output = ModInt<Num>; fn add(self, other: ModInt<Num>) -> ModInt<Num> { let mut d = self.0 + other.0; if d >= MOD { d -= MOD; } ModInt(d) } } impl AddAssign<ModInt<Num>> for ModInt<Num> { fn add_assign(&mut self, other: ModInt<Num>) { *self = *self + other; } } impl Sub<ModInt<Num>> for ModInt<Num> { type Output = ModInt<Num>; fn sub(self, other: ModInt<Num>) -> ModInt<Num> { let mut d = self.0 + MOD - other.0; if d >= MOD { d -= MOD; } ModInt(d) } } impl SubAssign<ModInt<Num>> for ModInt<Num> { fn sub_assign(&mut self, other: ModInt<Num>) { *self = *self - other; } } impl Mul<ModInt<Num>> for ModInt<Num> { type Output = ModInt<Num>; fn mul(self, other: ModInt<Num>) -> ModInt<Num> { ModInt(((self.0 as u64) * (other.0 as u64) % (MOD as u64)) as u32) } } impl MulAssign<ModInt<Num>> for ModInt<Num> { fn mul_assign(&mut self, other: ModInt<Num>) { *self = *self * other; } } impl Div<ModInt<Num>> for ModInt<Num> { type Output = ModInt<Num>; fn div(self, other: ModInt<Num>) -> ModInt<Num> { self * other.pow(MOD - 2) } } impl DivAssign<ModInt<Num>> for ModInt<Num> { fn div_assign(&mut self, other: ModInt<Num>) { *self = *self / other; } } impl Neg for ModInt<Num> { type Output = ModInt<Num>; fn neg(self) -> ModInt<Num> { ModInt(if self.0 == 0 { 0 } else { MOD - self.0 }) } } impl ModInt<Num> { pub fn new(v: u32) -> ModInt<Num> { ModInt(v % MOD) } pub fn pow(self, mut n: u32) -> ModInt<Num> { let mut t = ModInt::new(1); let mut s = self; while n > 0 { if (n & 1) == 1 { t *= s; } s *= s; n >>= 1; } t } } pub struct Precalc { n: usize, inv: Vec<ModInt<Num>>, fact: Vec<ModInt<Num>>, ifact: Vec<ModInt<Num>>, } impl Precalc { pub fn new(n: usize) -> Precalc { let mut inv = vec![ModInt(1); n + 1]; let mut fact = vec![ModInt(1); n + 1]; let mut ifact = vec![ModInt(1); n + 1]; for i in 1..(n + 1) { if i >= 2 { inv[i] = -inv[(MOD as usize) % i] * ModInt(MOD / (i as u32)); } fact[i] = ModInt(i as u32) * fact[i - 1]; ifact[i] = inv[i] * ifact[i - 1]; } Precalc { n: n, inv: inv, fact: fact, ifact: ifact, } } pub fn fact(&self, n: usize) -> ModInt<Num> { self.fact[n] } pub fn inv(&self, x: usize) -> ModInt<Num> { self.inv[x] } pub fn ifact(&self, x: usize) -> ModInt<Num> { self.ifact[x] } pub fn comb(&self, n: usize, k: usize) -> ModInt<Num> { if !(k <= n) { return ModInt(0); } self.fact[n] * self.ifact[k] * self.ifact[n - k] } } use std; impl std::fmt::Display for ModInt<Num> { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.0) } } } // ---------- end ModInt ---------- use modint::*; fn run() { let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); let mut it = s.trim().split_whitespace(); let n: usize = it.next().unwrap().parse().unwrap(); let m: usize = it.next().unwrap().parse().unwrap(); let d1: usize = it.next().unwrap().parse().unwrap(); let d2: usize = it.next().unwrap().parse().unwrap(); if 1 + d1 * (n - 1) > m { println!("0"); return; } let d = d2 - d1; let m = m - 1 - d1 * (n - 1); let pc = Precalc::new(n + m + 1); let mut ans = pc.comb(m + n, n); let mut sign = -ModInt(1); let mut i = 1; while i <= n - 1 && i * (d + 1) <= m { ans += sign * pc.comb(n - 1, i) * pc.comb(m + n - i * (d + 1), n); sign = -sign; i += 1; } println!("{}", ans); } fn main() { run(); }