結果

問題 No.533 Mysterious Stairs
ユーザー nu50218
提出日時 2019-09-02 21:12:35
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 686 bytes
コンパイル時間 1,468 ms
コンパイル使用メモリ 166,952 KB
実行使用メモリ 26,912 KB
最終ジャッジ日時 2024-12-17 16:53:59
合計ジャッジ時間 2,494 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const int INF = 1000000007;

int main() {
    int N;
    cin >> N;
    long long DP[N + 1][3] = {};
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < 3; j++) {
            int step = j + 1;
            if (i - step < 0) {
                continue;
            }
            if (i - step == 0) {
                DP[i][j] = 1;
                continue;
            }
            for (int k = 0; k < 3; k++) {
                if(j != k){
                    DP[i][j] += DP[i-step][k];
                    DP[i][j] %= INF;
                }
            }
        }
    }
    cout << (DP[N][0] + DP[N][1] + DP[N][2])%INF << endl;
}
0