結果
問題 | No.1172 Add Recursive Sequence |
ユーザー | noshi91 |
提出日時 | 2020-05-10 00:29:26 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 3,487 ms / 4,000 ms |
コード長 | 3,398 bytes |
コンパイル時間 | 14,719 ms |
コンパイル使用メモリ | 379,468 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-08 20:16:36 |
合計ジャッジ時間 | 23,063 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 3 ms
5,248 KB |
testcase_10 | AC | 28 ms
5,248 KB |
testcase_11 | AC | 25 ms
5,248 KB |
testcase_12 | AC | 98 ms
5,248 KB |
testcase_13 | AC | 88 ms
5,248 KB |
testcase_14 | AC | 1,147 ms
5,248 KB |
testcase_15 | AC | 3,439 ms
5,248 KB |
testcase_16 | AC | 1,190 ms
5,248 KB |
testcase_17 | AC | 3,487 ms
5,248 KB |
ソースコード
use std::io::{self, Read as _, Write as _}; struct Scanner<'a>(std::str::SplitWhitespace<'a>); impl<'a> Scanner<'a> { fn new(s: &'a str) -> Self { Self(s.split_whitespace()) } fn next<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, { let s = self.0.next().expect("found EOF"); match s.parse() { Ok(v) => v, Err(msg) => { println!( "parse error. T = {}, s = \"{}\": {:?}", std::any::type_name::<T>(), s, msg ); panic!() } } } } mod fp { use std::convert::From; use std::ops; const P: u32 = 1000000007; #[derive(Copy, Clone)] pub struct Fp(pub u32); impl From<i64> for Fp { fn from(mut x: i64) -> Fp { x %= P as i64; if x < 0 { x += P as i64; } Fp(x as u32) } } impl ops::Add<Fp> for Fp { type Output = Fp; fn add(mut self, rhs: Fp) -> Fp { self += rhs; self } } impl ops::AddAssign<Fp> for Fp { fn add_assign(&mut self, rhs: Fp) { self.0 += rhs.0; if self.0 >= P { self.0 -= P; } } } impl ops::Mul<Fp> for Fp { type Output = Fp; fn mul(mut self, rhs: Fp) -> Fp { self *= rhs; self } } impl ops::MulAssign<Fp> for Fp { fn mul_assign(&mut self, rhs: Fp) { self.0 = (self.0 as u64 * rhs.0 as u64 % P as u64) as u32; } } impl ops::Neg for Fp { type Output = Fp; fn neg(self) -> Fp { Fp(match self.0 { 0 => 0, s => P - s, }) } } impl ops::Sub<Fp> for Fp { type Output = Fp; fn sub(mut self, rhs: Fp) -> Fp { self -= rhs; self } } impl ops::SubAssign<Fp> for Fp { fn sub_assign(&mut self, rhs: Fp) { if self.0 < rhs.0 { self.0 += P; } self.0 -= rhs.0; } } impl std::iter::Sum for Fp { fn sum<I>(iter: I) -> Fp where I: Iterator<Item = Fp>, { iter.fold(Fp(0), |s, x| s + x) } } } use fp::Fp; fn main() { let mut stdin = String::new(); std::io::stdin().read_to_string(&mut stdin).unwrap(); let mut sc = Scanner::new(&stdin); let stdout = io::stdout(); let mut stdout = io::BufWriter::new(stdout.lock()); let k = sc.next(); let n = sc.next(); let m = sc.next(); let mut a = (0..k).map(|_| Fp(sc.next())).collect::<Vec<_>>(); let c = (0..k) .map(|_| Fp(sc.next())) .collect::<Vec<_>>() .into_iter() .rev() .collect::<Vec<_>>(); a.reserve_exact(n); for i in 0..n { a.push(c.iter().zip(&a[i..]).map(|(&c, &a)| c * a).sum()); } let mut x = vec![Fp(0); n]; for _ in 0..m { let (l, r): (usize, usize) = (sc.next(), sc.next()); for i in l..r { x[i] += a[i - l]; } } for Fp(x) in x { writeln!(stdout, "{}", x).unwrap(); } stdout.flush().unwrap(); }