結果

問題 No.314 ケンケンパ
ユーザー mine691mine691
提出日時 2018-07-10 22:49:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 564 bytes
コンパイル時間 574 ms
コンパイル使用メモリ 64,536 KB
実行使用メモリ 15,020 KB
最終ジャッジ日時 2023-10-11 23:47:06
合計ジャッジ時間 1,633 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
using namespace std;

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

int main() {
	int n;
	cin >> n;
	int 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