結果

問題 No.533 Mysterious Stairs
ユーザー Naoyk1212Naoyk1212
提出日時 2017-06-24 00:38:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 743 bytes
コンパイル時間 1,321 ms
コンパイル使用メモリ 159,300 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-04-15 01:12:48
合計ジャッジ時間 2,074 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 4 ms
6,944 KB
testcase_21 AC 5 ms
6,940 KB
testcase_22 AC 11 ms
7,808 KB
testcase_23 AC 28 ms
14,848 KB
testcase_24 AC 28 ms
15,104 KB
testcase_25 AC 4 ms
6,940 KB
testcase_26 AC 24 ms
13,312 KB
testcase_27 AC 9 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    int dp[n + 10][3];
    for(int i = 0; i <= n; i++){
        for(int j = 0; j < 3; j++){
            dp[i][j] = 0;
        }
    }
    dp[1][0] = 1;
    dp[2][1] = 1;
    dp[3][2] = 1;

    for(int i = 0; i < n; i++){
      for(int j = 0; j < 3; j++){
        for(int k = 0; k < 3; k++){
          //cerr << i << " " << j << " " << k << " " <<  dp[i][j] << endl;
          if(dp[i][j] > 0 && j != k){
            dp[i + k + 1][k] = (dp[i + k + 1][k] + dp[i][j]) % mod;
          }
        }
      }
    }

    long long ans = 0;
    for(int i = 0; i < 3; i++){
        ans = (ans + dp[n][i]) % mod;
    }
    cout << ans << endl;

}
0