結果

問題 No.533 Mysterious Stairs
ユーザー masamasa
提出日時 2017-06-23 23:10:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 579 bytes
コンパイル時間 583 ms
コンパイル使用メモリ 72,004 KB
実行使用メモリ 42,460 KB
最終ジャッジ日時 2024-04-15 01:01:56
合計ジャッジ時間 1,442 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 7 ms
7,552 KB
testcase_21 AC 7 ms
8,192 KB
testcase_22 AC 18 ms
18,192 KB
testcase_23 AC 39 ms
41,768 KB
testcase_24 AC 37 ms
42,460 KB
testcase_25 AC 7 ms
7,552 KB
testcase_26 AC 33 ms
36,988 KB
testcase_27 AC 14 ms
13,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

const int mod = 1e9 + 7;

int main() {
	int n;
	cin >> n;

	vector<vector<long long>> a(4, vector<long long>(n + 10, 0));
	a[1][1] = 1;
	a[2][2] = 1;
	a[3][3] = 1;

	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= 3; j++) {
			if (a[j][i] == 0) {
				continue;
			}

			for (int k = 1; k <= 3; k++) {
				if (k == j) {
					continue;
				}
				a[k][i+k] += a[j][i];
				a[k][i+k] %= mod;
			}

		}
	}

	int ans = (a[0][n] + a[1][n] + a[2][n] + a[3][n]) % mod;
	cout << ans << endl;
	return 0;
}
0