結果

問題 No.1681 +-*
ユーザー phsplsphspls
提出日時 2022-10-20 01:50:17
言語 Rust
(1.77.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 591 bytes
コンパイル時間 1,979 ms
コンパイル使用メモリ 145,008 KB
実行使用メモリ 16,392 KB
最終ジャッジ日時 2023-09-12 12:38:48
合計ジャッジ時間 3,523 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 24 ms
15,220 KB
testcase_06 AC 24 ms
15,208 KB
testcase_07 AC 24 ms
15,120 KB
testcase_08 AC 30 ms
16,316 KB
testcase_09 AC 30 ms
16,244 KB
testcase_10 AC 30 ms
16,324 KB
testcase_11 AC 31 ms
16,392 KB
testcase_12 AC 31 ms
16,304 KB
testcase_13 AC 16 ms
9,120 KB
testcase_14 AC 31 ms
16,384 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 30 ms
16,320 KB
testcase_18 AC 30 ms
16,332 KB
testcase_19 AC 31 ms
16,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const MOD: isize = 1e9 as isize + 7;

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<isize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let mut dp = vec![vec![0isize; 2]; n];
    dp[0][1] = a[0];
    for i in 0..n-1 {
        dp[i+1][0] = (dp[i][0] * 3 + dp[i][1] * 2) % MOD;
        dp[i+1][1] = dp[i][1] * a[i+1] % MOD;
    }
    println!("{}", (dp[n-1][0] + dp[n-1][1]) % MOD);
}
0