結果

問題 No.533 Mysterious Stairs
ユーザー pekempeypekempey
提出日時 2017-06-23 22:38:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 5,000 ms
コード長 971 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 75,864 KB
実行使用メモリ 57,864 KB
最終ジャッジ日時 2024-04-15 00:56:25
合計ジャッジ時間 1,933 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 3 ms
6,948 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 AC 3 ms
6,944 KB
testcase_20 AC 14 ms
9,344 KB
testcase_21 AC 15 ms
9,960 KB
testcase_22 AC 41 ms
24,108 KB
testcase_23 AC 100 ms
57,324 KB
testcase_24 AC 102 ms
57,864 KB
testcase_25 AC 13 ms
9,288 KB
testcase_26 AC 89 ms
50,384 KB
testcase_27 AC 28 ms
17,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

constexpr int MOD = 1e9 + 7;

struct modint {
	int n;
	modint(int n = 0) : n(n) {}
};

modint operator+(modint a, modint b) { return modint((a.n += b.n) >= MOD ? a.n - MOD : a.n); }
modint operator-(modint a, modint b) { return modint((a.n -= b.n) < 0 ? a.n + MOD : a.n); }
modint operator*(modint a, modint b) { return modint(1LL * a.n * b.n % MOD); }
modint &operator+=(modint &a, modint b) { return a = a + b; }
modint &operator-=(modint &a, modint b) { return a = a - b; }
modint &operator*=(modint &a, modint b) { return a = a * b; }

int main() {
	int n;
	std::cin >> n;
	std::vector<std::vector<modint>> dp(n + 10, std::vector<modint>(4));
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= 3; j++) {
			for (int k = 1; k <= 3; k++) {
				if (j != k) {
					dp[i + k][k] += dp[i][j];
				}
			}
		}
	}

	std::cout << (dp[n][1] + dp[n][2] + dp[n][3]).n << std::endl;
}
0