結果

問題 No.314 ケンケンパ
ユーザー hotpepsihotpepsi
提出日時 2015-12-07 01:08:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 1,000 ms
コード長 482 bytes
コンパイル時間 618 ms
コンパイル使用メモリ 53,424 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-12 18:44:59
合計ジャッジ時間 1,485 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,356 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 5 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>

using namespace std;

typedef long long LL;
const LL MOD = 1000000007;

int main(int argc, char *argv[])
{
	LL N;
	cin >> N;
	LL dp[2][3] = {};
	dp[0][0] = 1;
	for (int t = 0; t < N; ++t) {
		int prev = t & 1;
		int next = prev ^ 1;
		dp[next][0] = (dp[prev][1] + dp[prev][2]) % MOD;
		dp[next][1] = dp[prev][0];
		dp[next][2] = dp[prev][1];
	}
	LL ans = (dp[N & 1][0] + dp[N & 1][1] + dp[N & 1][2]) % MOD;
	cout << ans << endl;
	return 0;
}
0