結果

問題 No.533 Mysterious Stairs
ユーザー Daigo HIROOKADaigo HIROOKA
提出日時 2018-06-17 01:33:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 185 ms / 5,000 ms
コード長 604 bytes
コンパイル時間 3,072 ms
コンパイル使用メモリ 74,172 KB
実行使用メモリ 77,028 KB
最終ジャッジ日時 2023-09-13 06:17:57
合計ジャッジ時間 7,931 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
56,068 KB
testcase_01 AC 117 ms
55,848 KB
testcase_02 AC 118 ms
56,080 KB
testcase_03 AC 120 ms
56,092 KB
testcase_04 AC 118 ms
56,272 KB
testcase_05 AC 118 ms
55,960 KB
testcase_06 AC 117 ms
56,324 KB
testcase_07 AC 119 ms
55,956 KB
testcase_08 AC 119 ms
55,744 KB
testcase_09 AC 118 ms
56,232 KB
testcase_10 AC 120 ms
56,292 KB
testcase_11 AC 117 ms
54,860 KB
testcase_12 AC 117 ms
55,920 KB
testcase_13 AC 115 ms
55,888 KB
testcase_14 AC 117 ms
55,636 KB
testcase_15 AC 118 ms
56,032 KB
testcase_16 AC 120 ms
55,764 KB
testcase_17 AC 117 ms
56,204 KB
testcase_18 AC 119 ms
56,164 KB
testcase_19 AC 118 ms
55,936 KB
testcase_20 AC 136 ms
58,008 KB
testcase_21 AC 141 ms
60,352 KB
testcase_22 AC 150 ms
64,664 KB
testcase_23 AC 185 ms
76,752 KB
testcase_24 AC 184 ms
77,028 KB
testcase_25 AC 137 ms
57,972 KB
testcase_26 AC 176 ms
73,672 KB
testcase_27 AC 146 ms
62,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class No533{
	public static void main(String[] args){
		long mod = 1000000007;
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		long[][] dp = new long[3][N+1];
		dp[0][1] = 1;
		if(N > 1) dp[1][2] = 1;
		if(N > 2){
			dp[0][3] = 1;
			dp[1][3] = 1;
			dp[2][3] = 1;
		}
		for(int i = 4; i < N+1; i++){
			dp[0][i] = (dp[1][i-1] + dp[2][i-1])%mod;
			dp[1][i] = (dp[0][i-2] + dp[2][i-2])%mod;
			dp[2][i] = (dp[0][i-3] + dp[1][i-3])%mod;
		}
		long ans = dp[0][N];
		ans = (ans + dp[1][N])%mod;
		ans = (ans + dp[2][N])%mod;
		System.out.println(ans);
	}
}
0