結果
問題 | No.498 ワープクリスタル (給料日編) |
ユーザー | tanzaku |
提出日時 | 2017-03-24 23:43:02 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 3,295 bytes |
コンパイル時間 | 12,294 ms |
コンパイル使用メモリ | 405,460 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-06 01:41:00 |
合計ジャッジ時間 | 13,564 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 0 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 23 ms
5,376 KB |
testcase_05 | AC | 0 ms
5,376 KB |
testcase_06 | AC | 24 ms
5,376 KB |
testcase_07 | AC | 24 ms
5,376 KB |
testcase_08 | AC | 24 ms
5,376 KB |
testcase_09 | AC | 24 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 4 ms
5,376 KB |
testcase_12 | AC | 0 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 0 ms
5,376 KB |
testcase_15 | AC | 0 ms
5,376 KB |
testcase_16 | AC | 0 ms
5,376 KB |
testcase_17 | AC | 1 ms
5,376 KB |
testcase_18 | AC | 25 ms
5,376 KB |
testcase_19 | AC | 24 ms
5,376 KB |
testcase_20 | AC | 24 ms
5,376 KB |
testcase_21 | AC | 24 ms
5,376 KB |
testcase_22 | AC | 23 ms
5,376 KB |
testcase_23 | AC | 23 ms
5,376 KB |
testcase_24 | AC | 24 ms
5,376 KB |
ソースコード
const MOD: u64 = 1_000000000 + 7; #[derive(Debug)] struct Solver { gx: i64, gy: i64, x: Vec<i64>, y: Vec<i64>, c: Vec<usize>, comb: Vec<Vec<u64>>, used: Vec<usize>, } impl Solver { fn new() -> Self { let mut scanner = Scanner::new(); let gx = scanner.next_i64(); let gy = scanner.next_i64(); let n = scanner.next_usize(); let mut x = Vec::new(); let mut y = Vec::new(); let mut c = Vec::new(); for _ in 0..n { x.push(scanner.next_i64()); y.push(scanner.next_i64()); c.push(scanner.next_usize()); } let sum: usize = c.iter().sum(); let mut comb = vec![vec![0; sum+1]; sum+1]; for i in 0..sum+1 { comb[i][0] = 1; comb[i][i] = 1; for j in 1..i { comb[i][j] = comb[i-1][j-1] + comb[i-1][j]; if comb[i][j] >= MOD { comb[i][j] -= MOD } } } Solver { gx: gx, gy: gy, x: x, y: y, c: c, comb: comb, used: vec![0; n] } } fn calc(&mut self) -> u64 { let mut sum: usize = self.used.iter().sum(); let mut x = 0; let mut y = 0; let mut ans = 1_u64; for i in 0..self.used.len() { ans = ans * self.comb[sum][self.used[i]] % MOD; x += self.x[i] * self.used[i] as i64; y += self.y[i] * self.used[i] as i64; sum -= self.used[i]; } if x == self.gx && y == self.gy { ans } else { 0 } } fn rec(&mut self, idx: usize) -> u64 { if idx >= self.used.len() { return self.calc(); } let mut ans = 0; for i in 0..self.c[idx]+1 { self.used[idx] = i; ans += self.rec(idx + 1); } ans % MOD } } fn main() { let mut solver = Solver::new(); println!("{}", solver.rec(0)); } struct Scanner { reader: std::io::Stdin, tokens: std::collections::VecDeque<String>, } impl Scanner { fn new() -> Self { Scanner { reader: std::io::stdin(), tokens: std::collections::VecDeque::new(), } } fn next(&mut self) -> String { if self.tokens.is_empty() { let mut s = String::new(); loop { self.reader.read_line(&mut s).ok(); let s = s.trim(); if s.len() != 0 { for it in s.split_whitespace() { self.tokens.push_back(it.into()) } break; } } } self.tokens.pop_front().unwrap() } fn next_generics<T>(&mut self) -> T where T: std::str::FromStr + std::marker::Copy, <T as std::str::FromStr>::Err: std::fmt::Debug { self.next().parse().unwrap() } #[allow(dead_code)] fn next_i32(&mut self) -> i32 { self.next_generics::<i32>() } #[allow(dead_code)] fn next_i64(&mut self) -> i64 { self.next_generics::<i64>() } #[allow(dead_code)] fn next_u64(&mut self) -> u64 { self.next_generics::<u64>() } #[allow(dead_code)] fn next_usize(&mut self) -> usize { self.next_generics::<usize>() } }