結果

問題 No.533 Mysterious Stairs
ユーザー uenokuuenoku
提出日時 2017-10-26 08:01:18
言語 Rust
(1.77.0)
結果
AC  
実行時間 82 ms / 5,000 ms
コード長 1,329 bytes
コンパイル時間 13,646 ms
コンパイル使用メモリ 379,036 KB
実行使用メモリ 56,704 KB
最終ジャッジ日時 2024-05-01 14:58:41
合計ジャッジ時間 16,912 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
56,504 KB
testcase_01 AC 70 ms
56,572 KB
testcase_02 AC 69 ms
56,536 KB
testcase_03 AC 70 ms
56,572 KB
testcase_04 AC 69 ms
56,700 KB
testcase_05 AC 69 ms
56,512 KB
testcase_06 AC 70 ms
56,504 KB
testcase_07 AC 69 ms
56,532 KB
testcase_08 AC 68 ms
56,640 KB
testcase_09 AC 70 ms
56,564 KB
testcase_10 AC 70 ms
56,428 KB
testcase_11 AC 70 ms
56,568 KB
testcase_12 AC 70 ms
56,576 KB
testcase_13 AC 69 ms
56,484 KB
testcase_14 AC 69 ms
56,576 KB
testcase_15 AC 70 ms
56,704 KB
testcase_16 AC 71 ms
56,412 KB
testcase_17 AC 69 ms
56,576 KB
testcase_18 AC 70 ms
56,668 KB
testcase_19 AC 70 ms
56,520 KB
testcase_20 AC 71 ms
56,576 KB
testcase_21 AC 71 ms
56,576 KB
testcase_22 AC 73 ms
56,396 KB
testcase_23 AC 82 ms
56,568 KB
testcase_24 AC 82 ms
56,436 KB
testcase_25 AC 70 ms
56,576 KB
testcase_26 AC 80 ms
56,536 KB
testcase_27 AC 73 ms
56,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::{stdin, Read};
use std::str::FromStr;
#[allow(unused_imports)]
use std::{cmp, mem, process};
#[allow(unused_imports)]
use std::collections::{HashSet, BTreeMap, BTreeSet};

fn main() {
    let n: usize = read::<usize>();
    let mut dp = vec![vec![0; 4]; 1000105];
    dp[1][1] = 1;
    dp[2][2] = 1;
    dp[3][3] = 1;
    let modulo = 1000000007;
    for i in 1..n + 1 {
        for j in 1..4 {
            for k in 1..4 {
                if k != j {
                    dp[i + j][j] = (dp[i + j][j] + dp[i][k]) % modulo;
                }
            }
        }
    }
    println!("{}", ((dp[n][1] + dp[n][2]) % modulo + dp[n][3]) % modulo);
}


#[allow(dead_code)]
fn read_vec<T: FromStr>(n: usize) -> Vec<T> {
    let mut v = vec![];
    for _ in 0..n {
        let a = read::<T>();
        v.push(a);
    }
    v
}
#[allow(dead_code)]
fn read_str() -> Vec<char> {
    let s: String = read();
    s.chars().collect::<Vec<char>>()
}
#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().unwrap_or_else(
        |_| panic!("Faild to parse {}", s),
    )
}
0