結果
問題 |
No.801 エレベーター
|
ユーザー |
|
提出日時 | 2022-12-23 23:49:26 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 102 ms / 2,000 ms |
コード長 | 1,416 bytes |
コンパイル時間 | 10,365 ms |
コンパイル使用メモリ | 377,668 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-18 04:44:23 |
合計ジャッジ時間 | 13,132 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
const MOD: usize = 1e9 as usize + 7; fn main() { let mut nmk = String::new(); std::io::stdin().read_line(&mut nmk).ok(); let nmk: Vec<usize> = nmk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nmk[0]; let m = nmk[1]; let k = nmk[2]; let areas = (0..m).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); (temp[0]-1, temp[1]-1) }) .collect::<Vec<_>>(); let mut dp = vec![0usize; n]; dp[0] = 1; for _ in 0..k { let mut psummary = vec![0usize; n+1]; for i in 0..n { psummary[i+1] = psummary[i] + dp[i]; psummary[i+1] %= MOD; } let mut next_dp = vec![0usize; n]; for &(l, r) in areas.iter() { let people = MOD + psummary[r+1] - psummary[l]; let people = people % MOD; if people == 0 { continue; } next_dp[l] += people; next_dp[l] %= MOD; if r+1 < n { next_dp[r+1] += MOD - people; next_dp[r+1] %= MOD; } } for i in 0..n-1 { next_dp[i+1] += next_dp[i]; next_dp[i+1] %= MOD; } dp = next_dp; } println!("{}", dp[n-1]); }