結果

問題 No.314 ケンケンパ
ユーザー kou6839kou6839
提出日時 2015-12-07 00:19:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 297 ms / 1,000 ms
コード長 639 bytes
コンパイル時間 3,368 ms
コンパイル使用メモリ 73,060 KB
実行使用メモリ 89,804 KB
最終ジャッジ日時 2023-10-12 18:32:59
合計ジャッジ時間 6,076 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 297 ms
87,312 KB
testcase_01 AC 124 ms
55,844 KB
testcase_02 AC 124 ms
57,868 KB
testcase_03 AC 123 ms
55,416 KB
testcase_04 AC 125 ms
55,888 KB
testcase_05 AC 127 ms
55,988 KB
testcase_06 AC 125 ms
55,440 KB
testcase_07 AC 124 ms
55,856 KB
testcase_08 AC 123 ms
53,572 KB
testcase_09 AC 123 ms
55,712 KB
testcase_10 AC 123 ms
55,704 KB
testcase_11 AC 123 ms
56,020 KB
testcase_12 AC 124 ms
55,516 KB
testcase_13 AC 123 ms
56,260 KB
testcase_14 AC 124 ms
55,820 KB
testcase_15 AC 125 ms
55,808 KB
testcase_16 AC 129 ms
56,000 KB
testcase_17 AC 150 ms
60,536 KB
testcase_18 AC 206 ms
71,100 KB
testcase_19 AC 292 ms
89,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int mod = 1000000007;
		int[][] dp = new int[n+1][3];
		dp[0][0] = 1;
		for(int i=1;i<n+1;i++){
			for(int j=0;j<3;j++){
				if(j==0){
					dp[i][1]=dp[i-1][0];
					dp[i][1]%=mod;
				}
				else if(j==1){
					dp[i][2]+=dp[i-1][1];
					dp[i][2]%=mod;
					dp[i][0]+=dp[i-1][1];
					dp[i][0]%=mod;
				}else{
					dp[i][0]+=dp[i-1][2];
					dp[i][0]%=mod;
				}
			}
		}
		int ans = 0;
		for(int i=0;i<3;i++){
			ans+=dp[n][i];
			ans%=1000000007;
		}
		System.out.println(ans);
	}
}
0