結果

問題 No.533 Mysterious Stairs
ユーザー yuppe19 😺yuppe19 😺
提出日時 2017-06-23 23:18:28
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 701 bytes
コンパイル時間 406 ms
コンパイル使用メモリ 52,180 KB
最終ジャッジ日時 2024-04-15 01:05:48
合計ジャッジ時間 779 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:27: error: ‘pow’ was not declared in this scope
    6 |   constexpr int mod = int(pow(10, 9)) + 7;
      |                           ^~~
main.cpp:8:3: error: ‘vector’ was not declared in this scope
    8 |   vector<vector<int>> dp(4, vector<int>(n+1, 0)); // dp[4][n+1]
      |   ^~~~~~
main.cpp:3:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | using namespace std;
main.cpp:8:17: error: expected primary-expression before ‘int’
    8 |   vector<vector<int>> dp(4, vector<int>(n+1, 0)); // dp[4][n+1]
      |                 ^~~
main.cpp:10:3: error: ‘dp’ was not declared in this scope
   10 |   dp[0][0] = 1;
      |   ^~
main.cpp:7:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |   int n; scanf("%d", &n);
      |          ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

int main(void) {
  constexpr int mod = int(pow(10, 9)) + 7;
  int n; scanf("%d", &n);
  vector<vector<int>> dp(4, vector<int>(n+1, 0)); // dp[4][n+1]
  // [前回の移動段数][今の段数] := パターン数
  dp[0][0] = 1;
  for(int i=0; i<n; ++i) {
    for(int prev=0; prev<=3; ++prev) {
      for(int curr=1; curr<=3; ++curr) {
        if(prev == curr) { continue; }
        if(i + curr > n) { continue; }
        dp[curr][i+curr] += dp[prev][i];
        dp[curr][i+curr] %= mod;
      }
    }
  }
  int res = 0;
  for(int prev=1; prev<=3; ++prev) {
    res += dp[prev][n];
    res %= mod;
  }
  printf("%d\n", res);
  return 0;
}
0