結果

問題 No.801 エレベーター
ユーザー phsplsphspls
提出日時 2022-12-23 23:49:26
言語 Rust
(1.77.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 1,416 bytes
コンパイル時間 14,684 ms
コンパイル使用メモリ 379,024 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 04:38:25
合計ジャッジ時間 17,562 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 120 ms
5,376 KB
testcase_14 AC 120 ms
5,376 KB
testcase_15 AC 119 ms
5,376 KB
testcase_16 AC 120 ms
5,376 KB
testcase_17 AC 119 ms
5,376 KB
testcase_18 AC 119 ms
5,376 KB
testcase_19 AC 119 ms
5,376 KB
testcase_20 AC 121 ms
5,376 KB
testcase_21 AC 120 ms
5,376 KB
testcase_22 AC 119 ms
5,376 KB
testcase_23 AC 115 ms
5,376 KB
testcase_24 AC 114 ms
5,376 KB
testcase_25 AC 115 ms
5,376 KB
testcase_26 AC 115 ms
5,376 KB
testcase_27 AC 114 ms
5,376 KB
testcase_28 AC 118 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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]);
}
0