結果

問題 No.533 Mysterious Stairs
ユーザー SeiyaSeiya
提出日時 2017-07-23 16:48:21
言語 Rust
(1.77.0)
結果
AC  
実行時間 75 ms / 5,000 ms
コード長 1,030 bytes
コンパイル時間 878 ms
コンパイル使用メモリ 167,536 KB
実行使用メモリ 56,968 KB
最終ジャッジ日時 2024-04-17 16:52:49
合計ジャッジ時間 1,693 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 0 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 0 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 0 ms
6,944 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 10 ms
7,936 KB
testcase_21 AC 11 ms
8,576 KB
testcase_22 AC 31 ms
23,064 KB
testcase_23 AC 75 ms
55,920 KB
testcase_24 AC 74 ms
56,968 KB
testcase_25 AC 10 ms
7,936 KB
testcase_26 AC 66 ms
50,108 KB
testcase_27 AC 21 ms
15,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::stdin;

fn main(){
    let n: usize = getvec()[0];
    println!("{}", solve(n));
}

fn solve(n: usize) -> usize {
    let mut dp: Vec<Vec<_>> = Vec::new();
    dp.push(vec![1, 1, 1]);
    dp.push(vec![1, 0, 0]);
    dp.push(vec![0, 1, 0]);
    dp.push(vec![0, 0, 1]);
    for i in 1..n {
        dp[i+1][0] = (dp[i+1][0]+dp[i][1]+dp[i][2]) % 1000000007;
        dp[i+2][1] = (dp[i+2][1]+dp[i][0]+dp[i][2]) % 1000000007;
        let x = (dp[i][0]+dp[i][1]) % 1000000007;
        dp.push(vec![0, 0, x]);
    }
    dp[n].iter().fold(0, |acc, x| acc+x) % 1000000007
}

#[allow(dead_code)]
fn getline() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn getvec<T: std::str::FromStr>() -> Vec<T>{
    let line = getline();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn getpair() -> (usize, usize){
    let nm = getvec();
    (nm[0], nm[1])
}
0