結果

問題 No.533 Mysterious Stairs
ユーザー GrenacheGrenache
提出日時 2017-07-15 12:18:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 232 ms / 5,000 ms
コード長 1,092 bytes
コンパイル時間 3,683 ms
コンパイル使用メモリ 77,880 KB
実行使用メモリ 65,176 KB
最終ジャッジ日時 2024-04-16 21:43:11
合計ジャッジ時間 8,840 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
40,396 KB
testcase_01 AC 134 ms
41,112 KB
testcase_02 AC 134 ms
41,188 KB
testcase_03 AC 122 ms
40,296 KB
testcase_04 AC 135 ms
41,372 KB
testcase_05 AC 121 ms
40,176 KB
testcase_06 AC 133 ms
41,256 KB
testcase_07 AC 121 ms
40,500 KB
testcase_08 AC 136 ms
41,452 KB
testcase_09 AC 135 ms
41,380 KB
testcase_10 AC 135 ms
41,240 KB
testcase_11 AC 136 ms
41,528 KB
testcase_12 AC 120 ms
40,200 KB
testcase_13 AC 136 ms
41,244 KB
testcase_14 AC 133 ms
41,468 KB
testcase_15 AC 137 ms
41,716 KB
testcase_16 AC 137 ms
41,500 KB
testcase_17 AC 135 ms
41,640 KB
testcase_18 AC 141 ms
41,608 KB
testcase_19 AC 141 ms
41,936 KB
testcase_20 AC 187 ms
44,040 KB
testcase_21 AC 166 ms
44,352 KB
testcase_22 AC 205 ms
50,812 KB
testcase_23 AC 232 ms
64,968 KB
testcase_24 AC 229 ms
65,176 KB
testcase_25 AC 186 ms
44,296 KB
testcase_26 AC 228 ms
62,084 KB
testcase_27 AC 197 ms
48,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder533 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		final int MOD = 1_000_000_007;

		int n = sc.nextInt();

		long[][] dp = new long[3][n + 10];
		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++) {
				if (dp[j][i] == 0) {
					continue;
				}

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

		pr.println((dp[0][n] + dp[1][n] + dp[2][n]) % MOD);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0