結果

問題 No.1331 Moving Penguin
ユーザー ks2mks2m
提出日時 2021-01-08 21:59:30
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,345 ms / 1,500 ms
コード長 1,208 bytes
コンパイル時間 1,967 ms
コンパイル使用メモリ 74,480 KB
実行使用メモリ 337,012 KB
最終ジャッジ日時 2023-08-07 10:48:34
合計ジャッジ時間 51,842 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
57,096 KB
testcase_01 AC 42 ms
49,348 KB
testcase_02 AC 43 ms
49,604 KB
testcase_03 AC 44 ms
49,540 KB
testcase_04 AC 1,132 ms
302,464 KB
testcase_05 AC 1,123 ms
301,440 KB
testcase_06 AC 1,124 ms
301,388 KB
testcase_07 AC 1,120 ms
301,376 KB
testcase_08 AC 1,134 ms
312,724 KB
testcase_09 AC 1,112 ms
313,504 KB
testcase_10 AC 1,126 ms
312,628 KB
testcase_11 AC 1,123 ms
312,452 KB
testcase_12 AC 1,133 ms
312,604 KB
testcase_13 AC 1,129 ms
312,528 KB
testcase_14 AC 1,116 ms
312,764 KB
testcase_15 AC 1,126 ms
312,388 KB
testcase_16 AC 1,126 ms
312,668 KB
testcase_17 AC 1,109 ms
312,540 KB
testcase_18 AC 1,139 ms
312,712 KB
testcase_19 AC 1,136 ms
312,820 KB
testcase_20 AC 1,122 ms
313,492 KB
testcase_21 AC 1,130 ms
312,608 KB
testcase_22 AC 1,114 ms
313,012 KB
testcase_23 AC 1,138 ms
313,568 KB
testcase_24 AC 1,135 ms
312,628 KB
testcase_25 AC 1,137 ms
312,544 KB
testcase_26 AC 1,126 ms
302,344 KB
testcase_27 AC 1,137 ms
302,024 KB
testcase_28 AC 1,119 ms
302,308 KB
testcase_29 AC 1,134 ms
337,012 KB
testcase_30 AC 386 ms
104,420 KB
testcase_31 AC 645 ms
200,112 KB
testcase_32 AC 316 ms
106,388 KB
testcase_33 AC 462 ms
126,684 KB
testcase_34 AC 768 ms
199,304 KB
testcase_35 AC 1,221 ms
301,728 KB
testcase_36 AC 1,219 ms
301,584 KB
testcase_37 AC 1,209 ms
302,108 KB
testcase_38 AC 414 ms
117,904 KB
testcase_39 AC 1,244 ms
289,444 KB
testcase_40 AC 580 ms
142,356 KB
testcase_41 AC 1,120 ms
301,596 KB
testcase_42 AC 1,235 ms
301,656 KB
testcase_43 AC 1,196 ms
301,704 KB
testcase_44 AC 1,345 ms
301,664 KB
testcase_45 AC 1,282 ms
301,756 KB
testcase_46 AC 1,311 ms
301,192 KB
testcase_47 AC 1,286 ms
302,028 KB
testcase_48 AC 1,123 ms
313,016 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);
		long[][] dp = new long[rn + 1][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];
			dp[0][i + 1] %= mod;
			if (a[i] == 1) {
				dp[1][i + 2] += dp[0][i];
				dp[1][i + 2] %= mod;
			} else if (a[i] <= rn) {
				int c = i + a[i];
				if (c < n) {
					dp[a[i]][c] += dp[0][i];
					dp[a[i]][c] %= mod;
				}
			} else {
				for (int j = i + a[i]; j < n; j += a[i]) {
					dp[0][j] += dp[0][i];
					dp[0][j] %= mod;
				}
			}
		}
		System.out.println(dp[0][n - 1]);
	}
}
0