結果

問題 No.533 Mysterious Stairs
ユーザー tetsutetsu
提出日時 2017-06-23 23:44:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 605 bytes
コンパイル時間 464 ms
コンパイル使用メモリ 55,356 KB
実行使用メモリ 26,692 KB
最終ジャッジ日時 2024-04-15 01:08:06
合計ジャッジ時間 1,276 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,496 KB
testcase_01 AC 2 ms
7,624 KB
testcase_02 AC 3 ms
7,492 KB
testcase_03 AC 2 ms
7,628 KB
testcase_04 AC 2 ms
7,500 KB
testcase_05 AC 3 ms
7,496 KB
testcase_06 AC 2 ms
7,368 KB
testcase_07 AC 2 ms
7,624 KB
testcase_08 AC 3 ms
7,496 KB
testcase_09 AC 2 ms
7,492 KB
testcase_10 AC 2 ms
7,496 KB
testcase_11 AC 3 ms
7,624 KB
testcase_12 AC 3 ms
7,500 KB
testcase_13 AC 3 ms
7,368 KB
testcase_14 AC 2 ms
7,624 KB
testcase_15 AC 2 ms
7,496 KB
testcase_16 AC 2 ms
7,620 KB
testcase_17 AC 3 ms
7,496 KB
testcase_18 AC 3 ms
7,624 KB
testcase_19 AC 3 ms
7,368 KB
testcase_20 AC 5 ms
10,320 KB
testcase_21 AC 4 ms
10,476 KB
testcase_22 AC 7 ms
15,028 KB
testcase_23 AC 13 ms
26,692 KB
testcase_24 AC 12 ms
26,652 KB
testcase_25 AC 4 ms
10,376 KB
testcase_26 AC 11 ms
26,292 KB
testcase_27 AC 5 ms
13,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stdlib.h>

#define N 1000000
#define M 1000000007

using namespace std;

int main(void)
{
  static long step1[N]={0};
  static long step2[N] = {0};
  static long step3[N] = {0};
  int n;
  cin >> n;
  step1[0] = 1; step2[0] = 0; step3[0] = 0;
  step1[1] = 0; step2[1] = 1; step3[1] = 0;
  step1[2] = 1; step2[2] = 1; step3[2] = 1;

  for(int i = 3; i < n; i++) {
    step1[i] = (step2[i-1] + step3[i-1])%M;
    step2[i] = (step1[i-2] + step3[i-2])%M;
    step3[i] = (step1[i-3] + step2[i-3])%M;
  }
  cout << ((step1[n-1] + step2[n-1] + step3[n-1])%M) << endl;
  return 0;
}
0