結果

問題 No.533 Mysterious Stairs
ユーザー tentententen
提出日時 2020-09-10 08:54:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 166 ms / 5,000 ms
コード長 765 bytes
コンパイル時間 1,838 ms
コンパイル使用メモリ 71,704 KB
実行使用メモリ 65,288 KB
最終ジャッジ日時 2023-08-23 12:32:55
合計ジャッジ時間 6,737 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,900 KB
testcase_01 AC 119 ms
55,724 KB
testcase_02 AC 121 ms
55,592 KB
testcase_03 AC 119 ms
55,796 KB
testcase_04 AC 120 ms
55,564 KB
testcase_05 AC 121 ms
56,336 KB
testcase_06 AC 121 ms
55,464 KB
testcase_07 AC 122 ms
55,808 KB
testcase_08 AC 119 ms
55,612 KB
testcase_09 AC 122 ms
55,752 KB
testcase_10 AC 121 ms
56,020 KB
testcase_11 AC 120 ms
55,536 KB
testcase_12 AC 119 ms
53,688 KB
testcase_13 AC 119 ms
56,224 KB
testcase_14 AC 123 ms
55,668 KB
testcase_15 AC 122 ms
56,248 KB
testcase_16 AC 124 ms
55,752 KB
testcase_17 AC 126 ms
55,972 KB
testcase_18 AC 129 ms
55,964 KB
testcase_19 AC 128 ms
55,312 KB
testcase_20 AC 132 ms
56,192 KB
testcase_21 AC 130 ms
57,920 KB
testcase_22 AC 147 ms
57,952 KB
testcase_23 AC 166 ms
63,448 KB
testcase_24 AC 166 ms
65,288 KB
testcase_25 AC 130 ms
57,576 KB
testcase_26 AC 162 ms
64,464 KB
testcase_27 AC 142 ms
60,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int[][] dp;
    static final int MOD = 1000000007;
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	dp = new int[3][n + 5];
    	dp[0][1] = 1;
    	dp[1][2] = 1;
    	dp[2][3] = 1;
    	for (int i = 1; i < n; i++) {
    	    for (int j = 0; j < 3; j++) {
    	        for (int k = 0; k < 3; k++) {
    	            if (j == k) {
    	                continue;
    	            }
    	            dp[k][i + k + 1] += dp[j][i];
    	            dp[k][i + k + 1] %= MOD;
    	        }
    	    }
    	}
    	int ans = 0;
    	for (int i = 0; i < 3; i++) {
    	    ans += dp[i][n];
    	    ans %= MOD;
    	}
    	System.out.println(ans);
    }
}
0