結果
問題 |
No.801 エレベーター
|
ユーザー |
|
提出日時 | 2023-01-07 00:54:21 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 121 ms / 2,000 ms |
コード長 | 1,375 bytes |
コンパイル時間 | 12,832 ms |
コンパイル使用メモリ | 376,728 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-30 21:53:21 |
合計ジャッジ時間 | 16,020 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 lines = (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 lines.iter() { let sumval = MOD + psummary[r+1] - psummary[l]; let sumval = sumval % MOD; next_dp[l] += sumval; next_dp[l] %= MOD; if r+1 < n { next_dp[r+1] += MOD - sumval; 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]); }