結果

問題 No.314 ケンケンパ
ユーザー mine691mine691
提出日時 2018-07-10 22:50:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 1,000 ms
コード長 570 bytes
コンパイル時間 476 ms
コンパイル使用メモリ 63,500 KB
実行使用メモリ 26,788 KB
最終ジャッジ日時 2023-10-11 23:47:10
合計ジャッジ時間 1,558 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
using namespace std;

int INF = 1e9 + 7;//この数で割る

int main() {
	int n;
	cin >> n;
	long long dp[1000010][3];//DPの配列を確保
	for (int i = 0;i < 3;i++)dp[0][i] = 0;//長さ0なら0通り
	//長さ1のものはケンのみ
	dp[1][0] = 0;
	dp[1][1] = 1;
	dp[1][2] = 0;
	for (int i = 2;i <= n;i++) {
		//ケンの長さごとに計算
		dp[i][0] = (dp[i - 1][1] + dp[i - 1][2]) % INF;
		dp[i][1] = dp[i - 1][0] % INF;
		dp[i][2] = dp[i - 1][1] % INF;
	}
	//出力はdp[n]の和
	cout << (dp[n][0] + dp[n][1] + dp[n][2]) % INF << endl;
}
0