結果

問題 No.533 Mysterious Stairs
コンテスト
ユーザー pekempey
提出日時 2017-06-23 22:38:47
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 57 ms / 5,000 ms
コード長 971 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 702 ms
コンパイル使用メモリ 89,216 KB
実行使用メモリ 58,112 KB
最終ジャッジ日時 2026-04-20 04:51:07
合計ジャッジ時間 1,615 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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