結果

問題 No.314 ケンケンパ
ユーザー kitakitalilykitakitalily
提出日時 2019-05-19 00:52:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 172 ms / 1,000 ms
コード長 765 bytes
コンパイル時間 3,792 ms
コンパイル使用メモリ 74,988 KB
実行使用メモリ 66,876 KB
最終ジャッジ日時 2023-10-17 07:51:03
合計ジャッジ時間 7,393 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 172 ms
66,876 KB
testcase_01 AC 132 ms
57,388 KB
testcase_02 AC 133 ms
57,392 KB
testcase_03 AC 133 ms
57,392 KB
testcase_04 AC 133 ms
57,440 KB
testcase_05 AC 133 ms
57,384 KB
testcase_06 AC 134 ms
57,404 KB
testcase_07 AC 134 ms
57,400 KB
testcase_08 AC 133 ms
57,612 KB
testcase_09 AC 136 ms
57,552 KB
testcase_10 AC 134 ms
57,468 KB
testcase_11 AC 134 ms
57,440 KB
testcase_12 AC 136 ms
57,516 KB
testcase_13 AC 135 ms
57,380 KB
testcase_14 AC 134 ms
57,404 KB
testcase_15 AC 135 ms
57,420 KB
testcase_16 AC 137 ms
57,564 KB
testcase_17 AC 150 ms
59,508 KB
testcase_18 AC 159 ms
62,160 KB
testcase_19 AC 170 ms
66,668 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