結果

問題 No.533 Mysterious Stairs
ユーザー d2verbd2verb
提出日時 2017-10-05 16:55:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 595 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 54,920 KB
実行使用メモリ 18,944 KB
最終ジャッジ日時 2024-04-28 07:37:25
合計ジャッジ時間 1,419 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 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 1 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 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 5 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 13 ms
9,216 KB
testcase_23 AC 32 ms
18,816 KB
testcase_24 AC 32 ms
18,944 KB
testcase_25 AC 5 ms
5,376 KB
testcase_26 AC 26 ms
16,768 KB
testcase_27 AC 8 ms
7,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

const int mod = 1000000007;
int dp[1000001][4];

int main(void) {
    int N;
    cin >> N;

    dp[1][1] = 1;
    dp[2][2] = 1; 
    dp[3][1] = 1; 
    dp[3][2] = 1; 
    dp[3][3] = 1; 

    for (int i = 4; i <= N; i++) {
        for (int j = 1; j <= 3; j++) {
            for (int k = 1; k <= 3; k++) {
                if (j == k) continue;
                dp[i][j] = (dp[i][j] + dp[i-j][k]) % mod;
            }
        }
    }

    int ans = 0;
    for (int i = 1; i <= 3; i++) ans = (ans + dp[N][i]) % mod;

    cout << ans << endl;
    return 0;
}
0