結果

問題 No.533 Mysterious Stairs
ユーザー face4face4
提出日時 2018-08-26 17:27:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 569 bytes
コンパイル時間 477 ms
コンパイル使用メモリ 64,436 KB
実行使用メモリ 28,772 KB
最終ジャッジ日時 2023-09-13 19:20:13
合計ジャッジ時間 2,251 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,488 KB
testcase_01 AC 3 ms
9,672 KB
testcase_02 AC 3 ms
9,496 KB
testcase_03 AC 3 ms
9,628 KB
testcase_04 AC 2 ms
9,496 KB
testcase_05 AC 3 ms
9,540 KB
testcase_06 AC 3 ms
9,672 KB
testcase_07 AC 3 ms
9,488 KB
testcase_08 AC 3 ms
9,628 KB
testcase_09 AC 3 ms
9,504 KB
testcase_10 AC 3 ms
9,504 KB
testcase_11 AC 3 ms
9,488 KB
testcase_12 AC 3 ms
9,676 KB
testcase_13 AC 3 ms
9,552 KB
testcase_14 AC 3 ms
9,484 KB
testcase_15 AC 3 ms
9,484 KB
testcase_16 AC 3 ms
9,556 KB
testcase_17 AC 3 ms
9,616 KB
testcase_18 AC 3 ms
9,488 KB
testcase_19 AC 3 ms
9,488 KB
testcase_20 AC 5 ms
13,584 KB
testcase_21 AC 6 ms
13,704 KB
testcase_22 AC 10 ms
19,724 KB
testcase_23 AC 18 ms
28,432 KB
testcase_24 AC 19 ms
28,772 KB
testcase_25 AC 5 ms
13,584 KB
testcase_26 AC 16 ms
28,060 KB
testcase_27 AC 7 ms
15,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

typedef long long ll;
const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;

    static ll dp[4][1000005] = {};

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

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

    cout << (dp[1][n] + dp[2][n] + dp[3][n]) % mod << endl;

    return 0;
}
0