結果

問題 No.1331 Moving Penguin
ユーザー ks2mks2m
提出日時 2021-01-08 22:33:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,184 ms / 1,500 ms
コード長 1,140 bytes
コンパイル時間 1,811 ms
コンパイル使用メモリ 73,792 KB
実行使用メモリ 331,960 KB
最終ジャッジ日時 2023-08-07 11:02:01
合計ジャッジ時間 49,671 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
57,460 KB
testcase_01 AC 41 ms
49,360 KB
testcase_02 AC 40 ms
49,272 KB
testcase_03 AC 41 ms
49,564 KB
testcase_04 AC 1,098 ms
298,336 KB
testcase_05 AC 1,068 ms
297,940 KB
testcase_06 AC 1,066 ms
298,180 KB
testcase_07 AC 1,074 ms
297,968 KB
testcase_08 AC 1,097 ms
313,668 KB
testcase_09 AC 1,088 ms
312,780 KB
testcase_10 AC 1,085 ms
310,100 KB
testcase_11 AC 1,159 ms
313,088 KB
testcase_12 AC 1,091 ms
310,724 KB
testcase_13 AC 1,084 ms
312,352 KB
testcase_14 AC 1,088 ms
312,512 KB
testcase_15 AC 1,084 ms
312,276 KB
testcase_16 AC 1,095 ms
312,556 KB
testcase_17 AC 1,088 ms
312,396 KB
testcase_18 AC 1,091 ms
312,304 KB
testcase_19 AC 1,086 ms
312,616 KB
testcase_20 AC 1,083 ms
313,148 KB
testcase_21 AC 1,067 ms
312,616 KB
testcase_22 AC 1,082 ms
312,760 KB
testcase_23 AC 1,088 ms
312,596 KB
testcase_24 AC 1,100 ms
312,588 KB
testcase_25 AC 1,081 ms
312,684 KB
testcase_26 AC 1,080 ms
298,840 KB
testcase_27 AC 1,079 ms
298,472 KB
testcase_28 AC 1,165 ms
298,104 KB
testcase_29 AC 1,109 ms
331,960 KB
testcase_30 AC 373 ms
104,140 KB
testcase_31 AC 620 ms
199,352 KB
testcase_32 AC 345 ms
107,268 KB
testcase_33 AC 464 ms
127,288 KB
testcase_34 AC 758 ms
199,120 KB
testcase_35 AC 1,115 ms
298,380 KB
testcase_36 AC 1,093 ms
298,796 KB
testcase_37 AC 1,091 ms
298,488 KB
testcase_38 AC 401 ms
117,596 KB
testcase_39 AC 1,184 ms
285,912 KB
testcase_40 AC 547 ms
141,832 KB
testcase_41 AC 1,104 ms
298,956 KB
testcase_42 AC 1,100 ms
298,320 KB
testcase_43 AC 1,115 ms
298,224 KB
testcase_44 AC 1,129 ms
298,364 KB
testcase_45 AC 1,132 ms
298,232 KB
testcase_46 AC 1,137 ms
298,424 KB
testcase_47 AC 1,139 ms
298,896 KB
testcase_48 AC 1,087 ms
312,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		int mod = 1000000007;
		int rn = (int) Math.sqrt(n) - 2;
		if (rn < 2) {
			rn = 2;
		}
		long[][] dp = new long[rn][n + 2];
		dp[0][0] = 1;
		for (int i = 0; i < n; i++) {
			for (int j = 1; j < rn; j++) {
				int p = i - j;
				if (p < 0) {
					break;
				}
				dp[j][i] += dp[j][p];
				dp[j][i] %= mod;
			}
			for (int j = 1; j < rn; j++) {
				dp[0][i] += dp[j][i];
			}
			dp[0][i] %= mod;

			dp[0][i + 1] += dp[0][i];
			if (a[i] == 1) {
				dp[1][i + 2] += dp[0][i];
			} else if (a[i] < rn) {
				int c = i + a[i];
				if (c < n) {
					dp[a[i]][c] += dp[0][i];
				}
			} else {
				for (int j = i + a[i]; j < n; j += a[i]) {
					dp[0][j] += dp[0][i];
				}
			}
		}
		System.out.println(dp[0][n - 1]);
	}
}
0