結果

問題 No.533 Mysterious Stairs
コンテスト
ユーザー siman
提出日時 2021-09-07 16:21:34
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 1,083 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,401 ms
コンパイル使用メモリ 147,712 KB
実行使用メモリ 34,688 KB
最終ジャッジ日時 2026-05-29 13:36:42
合計ジャッジ時間 6,803 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:21:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   21 |   ll dp[N + 4][4];
      |         ^~~~~
main.cpp:21:9: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:19:7: note: declared here
   19 |   int N;
      |       ^
1 warning generated.

ソースコード

diff #
raw source code

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  ll dp[N + 4][4];
  memset(dp, 0, sizeof(dp));
  dp[1][1] = 1;
  dp[2][2] = 1;
  dp[3][3] = 1;

  for (int i = 0; i < N; ++i) {
    for (int j = 1; j <= 3; ++j) {
      switch(j) {
        case 1:
          dp[i + 2][2] += dp[i][1];
          dp[i + 3][3] += dp[i][1];
          dp[i + 2][2] %= MOD;
          dp[i + 3][3] %= MOD;
          break;
        case 2:
          dp[i + 1][1] += dp[i][2];
          dp[i + 3][3] += dp[i][2];
          dp[i + 1][1] %= MOD;
          dp[i + 3][3] %= MOD;
          break;
        case 3:
          dp[i + 1][1] += dp[i][3];
          dp[i + 2][2] += dp[i][3];
          dp[i + 1][1] %= MOD;
          dp[i + 2][2] %= MOD;
          break;
      }
    }
  }

  cout << (dp[N][1] + dp[N][2] + dp[N][3]) % MOD << endl;

  return 0;
}
0