結果

問題 No.533 Mysterious Stairs
ユーザー cympfhcympfh
提出日時 2017-06-30 17:49:45
言語 Rust
(1.77.0)
結果
AC  
実行時間 80 ms / 5,000 ms
コード長 1,958 bytes
コンパイル時間 1,456 ms
コンパイル使用メモリ 164,112 KB
実行使用メモリ 56,480 KB
最終ジャッジ日時 2024-04-15 05:50:46
合計ジャッジ時間 2,654 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 0 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 10 ms
7,936 KB
testcase_21 AC 10 ms
8,576 KB
testcase_22 AC 31 ms
22,784 KB
testcase_23 AC 78 ms
55,808 KB
testcase_24 AC 80 ms
56,480 KB
testcase_25 AC 10 ms
7,936 KB
testcase_26 AC 69 ms
49,000 KB
testcase_27 AC 21 ms
15,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

#[allow(unused_macros)]
macro_rules! trace {
    ($var:expr) => ({
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    })
}
#[allow(unused_macros)]
macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) }

const M: usize = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut dp = vec![vec![0; 3]; n + 8];

    // for k in 0..3 { dp[0][k] = 1; }
    for i in 0..(n + 1) {
        for k in 0..3 {
            if i == 0 {
                dp[i + k + 1][k] += 1;
            } else {
                dp[i + k + 1][k] += dp[i][(k + 1) % 3] + dp[i][(k + 2) % 3];
            }
            dp[i + k + 1][k] %= M;
        }
    }
    let ans = (dp[n][0] + dp[n][1] + dp[n][2]) % M;
    println!("{}", ans);
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
    fn get_char(&mut self) -> char {
        self.reserve();
        let head = self.buffer[0].chars().nth(0).unwrap();
        let tail = String::from( &self.buffer[0][1..] );
        if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }
        head
    }
}
0