結果

問題 No.533 Mysterious Stairs
ユーザー ミドリムシミドリムシ
提出日時 2018-03-01 17:48:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 5,000 ms
コード長 689 bytes
コンパイル時間 521 ms
コンパイル使用メモリ 69,112 KB
実行使用メモリ 76,260 KB
最終ジャッジ日時 2023-08-26 20:22:37
合計ジャッジ時間 2,127 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
34,720 KB
testcase_01 AC 10 ms
34,664 KB
testcase_02 AC 9 ms
34,676 KB
testcase_03 AC 10 ms
34,624 KB
testcase_04 AC 10 ms
34,652 KB
testcase_05 AC 10 ms
34,604 KB
testcase_06 AC 10 ms
34,600 KB
testcase_07 AC 9 ms
34,564 KB
testcase_08 AC 10 ms
34,592 KB
testcase_09 AC 9 ms
34,744 KB
testcase_10 AC 9 ms
34,568 KB
testcase_11 AC 10 ms
34,752 KB
testcase_12 AC 10 ms
34,672 KB
testcase_13 AC 10 ms
34,712 KB
testcase_14 AC 10 ms
34,904 KB
testcase_15 AC 11 ms
34,636 KB
testcase_16 AC 10 ms
34,696 KB
testcase_17 AC 11 ms
34,784 KB
testcase_18 AC 11 ms
34,960 KB
testcase_19 AC 11 ms
35,136 KB
testcase_20 AC 18 ms
39,232 KB
testcase_21 AC 19 ms
39,728 KB
testcase_22 AC 36 ms
50,556 KB
testcase_23 AC 74 ms
75,740 KB
testcase_24 AC 75 ms
76,260 KB
testcase_25 AC 19 ms
39,384 KB
testcase_26 AC 67 ms
70,512 KB
testcase_27 AC 27 ms
45,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int N;

long dp[1000000][4];

long jump(int now, int back_jump){
    if(now >= N){
        return now == N;
    }else if(dp[now][back_jump] != -1){
        return dp[now][back_jump];
    }else{
        long ans = 0;
        for(int i = 1; i <= 3; i++){
            if(i != back_jump){
                ans += jump(now + i, i);
            }
        }
        return dp[now][back_jump] = ans % long(1e9 + 7);
    }
}

int main(){
    cin >> N;
    dp[0][0] = -1;
    for(int i = 0; i < 1000000; i++){
        dp[i][1] = -1;
        dp[i][2] = -1;
        dp[i][3] = -1;
    }
    cout << jump(0, 0) << endl;
}
0