結果

問題 No.1331 Moving Penguin
ユーザー ks2mks2m
提出日時 2021-01-08 21:59:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,492 ms / 1,500 ms
コード長 1,208 bytes
コンパイル時間 2,082 ms
コンパイル使用メモリ 76,608 KB
実行使用メモリ 321,512 KB
最終ジャッジ日時 2024-04-25 04:42:11
合計ジャッジ時間 58,682 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
46,652 KB
testcase_01 AC 51 ms
36,944 KB
testcase_02 AC 51 ms
36,892 KB
testcase_03 AC 52 ms
36,976 KB
testcase_04 AC 1,281 ms
289,564 KB
testcase_05 AC 1,261 ms
289,892 KB
testcase_06 AC 1,274 ms
289,980 KB
testcase_07 AC 1,266 ms
290,128 KB
testcase_08 AC 1,259 ms
302,340 KB
testcase_09 AC 1,267 ms
302,552 KB
testcase_10 AC 1,237 ms
301,588 KB
testcase_11 AC 1,230 ms
301,672 KB
testcase_12 AC 1,261 ms
302,460 KB
testcase_13 AC 1,244 ms
301,656 KB
testcase_14 AC 1,269 ms
302,424 KB
testcase_15 AC 1,269 ms
302,376 KB
testcase_16 AC 1,280 ms
302,304 KB
testcase_17 AC 1,274 ms
302,332 KB
testcase_18 AC 1,272 ms
302,536 KB
testcase_19 AC 1,292 ms
302,360 KB
testcase_20 AC 1,255 ms
301,440 KB
testcase_21 AC 1,289 ms
302,308 KB
testcase_22 AC 1,284 ms
302,300 KB
testcase_23 AC 1,245 ms
301,736 KB
testcase_24 AC 1,274 ms
302,288 KB
testcase_25 AC 1,265 ms
301,620 KB
testcase_26 AC 1,308 ms
289,956 KB
testcase_27 AC 1,310 ms
290,560 KB
testcase_28 AC 1,324 ms
289,800 KB
testcase_29 AC 1,331 ms
321,512 KB
testcase_30 AC 429 ms
93,540 KB
testcase_31 AC 758 ms
187,432 KB
testcase_32 AC 393 ms
95,476 KB
testcase_33 AC 536 ms
116,284 KB
testcase_34 AC 886 ms
189,408 KB
testcase_35 AC 1,431 ms
290,244 KB
testcase_36 AC 1,379 ms
290,356 KB
testcase_37 AC 1,413 ms
290,380 KB
testcase_38 AC 469 ms
108,916 KB
testcase_39 AC 1,451 ms
278,736 KB
testcase_40 AC 637 ms
130,640 KB
testcase_41 AC 1,284 ms
290,460 KB
testcase_42 AC 1,423 ms
290,584 KB
testcase_43 AC 1,414 ms
290,452 KB
testcase_44 AC 1,411 ms
290,524 KB
testcase_45 AC 1,486 ms
300,724 KB
testcase_46 AC 1,492 ms
300,464 KB
testcase_47 AC 1,487 ms
300,532 KB
testcase_48 AC 1,279 ms
302,540 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