結果

問題 No.533 Mysterious Stairs
ユーザー masamasa
提出日時 2017-06-23 23:10:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 5,000 ms
コード長 579 bytes
コンパイル時間 620 ms
コンパイル使用メモリ 71,400 KB
実行使用メモリ 42,208 KB
最終ジャッジ日時 2023-07-27 12:56:45
合計ジャッジ時間 1,983 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 7 ms
7,352 KB
testcase_21 AC 8 ms
7,860 KB
testcase_22 AC 19 ms
18,072 KB
testcase_23 AC 39 ms
41,692 KB
testcase_24 AC 40 ms
42,208 KB
testcase_25 AC 7 ms
7,524 KB
testcase_26 AC 35 ms
36,676 KB
testcase_27 AC 14 ms
12,812 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