結果

問題 No.533 Mysterious Stairs
ユーザー snrnsidysnrnsidy
提出日時 2021-11-19 00:12:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 5,000 ms
コード長 677 bytes
コンパイル時間 2,206 ms
コンパイル使用メモリ 198,192 KB
実行使用メモリ 34,616 KB
最終ジャッジ日時 2023-08-27 19:05:19
合計ジャッジ時間 3,348 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 8 ms
6,844 KB
testcase_21 AC 8 ms
7,220 KB
testcase_22 AC 22 ms
15,320 KB
testcase_23 AC 50 ms
34,248 KB
testcase_24 AC 51 ms
34,616 KB
testcase_25 AC 8 ms
6,928 KB
testcase_26 AC 45 ms
30,440 KB
testcase_27 AC 15 ms
11,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const long long int MOD = 1e9 + 7;
long long int dp[1000001][4];
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

    dp[0][0] = 1;
    int n;

    cin >> n;

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

    long long int res = dp[n][0] + dp[n][1] + dp[n][2] + dp[n][3];
    res%=MOD;

    cout << res << '\n';
    
	return 0;
}
0