結果

問題 No.314 ケンケンパ
ユーザー GrenacheGrenache
提出日時 2015-12-07 00:16:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 165 ms / 1,000 ms
コード長 766 bytes
コンパイル時間 3,434 ms
コンパイル使用メモリ 76,656 KB
実行使用メモリ 65,728 KB
最終ジャッジ日時 2023-10-12 18:27:43
合計ジャッジ時間 7,400 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 165 ms
65,728 KB
testcase_01 AC 125 ms
55,824 KB
testcase_02 AC 125 ms
55,700 KB
testcase_03 AC 125 ms
56,028 KB
testcase_04 AC 126 ms
55,736 KB
testcase_05 AC 124 ms
56,104 KB
testcase_06 AC 125 ms
55,824 KB
testcase_07 AC 124 ms
55,456 KB
testcase_08 AC 125 ms
55,920 KB
testcase_09 AC 123 ms
56,320 KB
testcase_10 AC 125 ms
55,980 KB
testcase_11 AC 124 ms
55,720 KB
testcase_12 AC 123 ms
55,472 KB
testcase_13 AC 125 ms
56,068 KB
testcase_14 AC 125 ms
56,000 KB
testcase_15 AC 125 ms
56,224 KB
testcase_16 AC 128 ms
56,092 KB
testcase_17 AC 141 ms
58,240 KB
testcase_18 AC 152 ms
60,448 KB
testcase_19 AC 164 ms
65,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder314 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        final int MOD = 1_000_000_007;

        int n = sc.nextInt();

        int[][] dp = new int[3][n];
        dp[1][0] = 1;

        for (int i = 0; i < n - 1; i++) {
        	for (int j = 0; j < 3; j++) {
        		if (j < 2) {
        			dp[j + 1][i + 1] = (dp[j + 1][i + 1] + dp[j][i]) % MOD;
        		}
        		if (j != 0) {
        			dp[0][i + 1] = (dp[0][i + 1] + dp[j][i]) % MOD;
        		}
        	}
        }

        int ret = 0;
        for (int i = 0; i < 3; i++) {
        	ret += dp[i][n - 1];
        	ret %= MOD;
        }

        System.out.println(ret);

        sc.close();
    }
}
0