結果

問題 No.533 Mysterious Stairs
ユーザー olpheolphe
提出日時 2017-06-23 22:23:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 1,465 bytes
コンパイル時間 901 ms
コンパイル使用メモリ 110,128 KB
実行使用メモリ 37,940 KB
最終ジャッジ日時 2023-08-19 03:37:33
合計ジャッジ時間 2,720 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
37,804 KB
testcase_01 AC 10 ms
37,872 KB
testcase_02 AC 10 ms
37,728 KB
testcase_03 AC 10 ms
37,808 KB
testcase_04 AC 10 ms
37,756 KB
testcase_05 AC 10 ms
37,940 KB
testcase_06 AC 10 ms
37,880 KB
testcase_07 AC 10 ms
37,748 KB
testcase_08 AC 10 ms
37,756 KB
testcase_09 AC 9 ms
37,812 KB
testcase_10 AC 10 ms
37,868 KB
testcase_11 AC 9 ms
37,812 KB
testcase_12 AC 10 ms
37,868 KB
testcase_13 AC 10 ms
37,744 KB
testcase_14 AC 10 ms
37,872 KB
testcase_15 AC 10 ms
37,752 KB
testcase_16 AC 11 ms
37,744 KB
testcase_17 AC 10 ms
37,724 KB
testcase_18 AC 10 ms
37,808 KB
testcase_19 AC 10 ms
37,812 KB
testcase_20 AC 11 ms
37,764 KB
testcase_21 AC 12 ms
37,872 KB
testcase_22 AC 12 ms
37,728 KB
testcase_23 AC 15 ms
37,808 KB
testcase_24 AC 14 ms
37,812 KB
testcase_25 AC 9 ms
37,720 KB
testcase_26 AC 15 ms
37,724 KB
testcase_27 AC 10 ms
37,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;
list<long long int> Prime(int M) {
	list<long long int>P;
	P.push_back(2);
	P.push_back(3);
	for (int i = 5; i <= M; i += 6) {
		bool flag = true;
		for (auto j : P) {
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i);
		flag = true;
		for (auto j : P) {
			if ((i + 2) % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i + 2);
	}
	return P;
}
long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H;
long long int ans;

int main() {
	ios::sync_with_stdio(false);
	long long int dp[1100001][4] = {};
	dp[1][1] = 1;
	dp[2][2] = 1;
	dp[3][3] = 1;
	cin >> N;
	for (int i = 1; i < N; i++) {
		dp[i + 1][1] = dp[i][2] + dp[i][3];
		dp[i + 1][1] %= MOD;
		dp[i + 2][2] = dp[i][1] + dp[i][3];
		dp[i + 2][2] %= MOD;
		dp[i + 3][3] = dp[i][1] + dp[i][2];
		dp[i + 3][3] %= MOD;
	}
	ans = dp[N][1] + dp[N][2] + dp[N][3];
	ans %= MOD;
	cout << ans << endl;
	return 0;
}
0