結果
問題 | No.1043 直列大学 |
ユーザー | Yukino DX. |
提出日時 | 2024-09-10 11:33:10 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 198 ms / 2,000 ms |
コード長 | 4,214 bytes |
コンパイル時間 | 14,162 ms |
コンパイル使用メモリ | 383,576 KB |
実行使用メモリ | 77,696 KB |
最終ジャッジ日時 | 2024-09-10 11:33:27 |
合計ジャッジ時間 | 16,291 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,812 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 1 ms
6,944 KB |
testcase_09 | AC | 3 ms
6,944 KB |
testcase_10 | AC | 8 ms
6,940 KB |
testcase_11 | AC | 73 ms
29,392 KB |
testcase_12 | AC | 198 ms
77,696 KB |
testcase_13 | AC | 79 ms
41,472 KB |
testcase_14 | AC | 89 ms
40,008 KB |
testcase_15 | AC | 103 ms
40,704 KB |
testcase_16 | AC | 86 ms
34,644 KB |
testcase_17 | AC | 48 ms
22,008 KB |
testcase_18 | AC | 42 ms
21,888 KB |
testcase_19 | AC | 78 ms
39,936 KB |
testcase_20 | AC | 42 ms
21,952 KB |
testcase_21 | AC | 69 ms
38,656 KB |
testcase_22 | AC | 71 ms
36,736 KB |
testcase_23 | AC | 110 ms
41,864 KB |
testcase_24 | AC | 53 ms
24,960 KB |
testcase_25 | AC | 77 ms
34,560 KB |
testcase_26 | AC | 84 ms
38,656 KB |
testcase_27 | AC | 31 ms
23,296 KB |
testcase_28 | AC | 47 ms
34,304 KB |
testcase_29 | AC | 5 ms
6,940 KB |
testcase_30 | AC | 71 ms
53,376 KB |
ソースコード
use proconio::input; fn main() { input! { n:usize, m:usize, v:[usize;n], r:[usize;m], a:usize, b:usize, } let sum_v = v.iter().sum::<usize>(); let sum_r = r.iter().sum::<usize>(); let dp_v = calc_dp(&v, n); let dp_r = calc_dp(&r, m); let cum_dp_v = dp_v .iter() .scan(ModInt::new(0), |cum, dpi_v| { *cum += *dpi_v; Some(*cum) }) .collect::<Vec<_>>(); let mut ans = ModInt::<MOD>::new(0); for i in 1..=sum_r { ans += dp_r[i] * (cum_dp_v[(b * i).min(sum_v)] - cum_dp_v[(a * i - 1).min(sum_v)]); } println!("{}", ans); } fn calc_dp(a: &Vec<usize>, n: usize) -> Vec<ModInt<MOD>> { let sum_a = a.iter().sum::<usize>(); let mut dp = vec![vec![ModInt::<MOD>::new(0); sum_a + 1]; n + 1]; dp[0][0] = ModInt::new(1); for i in 0..n { for j in 0..=sum_a { dp[i + 1][j] = dp[i + 1][j] + dp[i][j]; if j + a[i] <= sum_a { dp[i + 1][j + a[i]] = dp[i + 1][j + a[i]] + dp[i][j]; } } } dp[n].clone() } const MOD: usize = 1000000007; use modint::*; 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 } } }