結果

問題 No.1331 Moving Penguin
ユーザー ks2mks2m
提出日時 2021-01-08 22:29:00
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,236 bytes
コンパイル時間 2,179 ms
コンパイル使用メモリ 76,716 KB
実行使用メモリ 321,144 KB
最終ジャッジ日時 2024-04-25 04:51:30
合計ジャッジ時間 51,952 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 149 ms
46,728 KB
testcase_01 AC 51 ms
36,968 KB
testcase_02 AC 52 ms
36,840 KB
testcase_03 AC 52 ms
37,040 KB
testcase_04 AC 1,260 ms
287,944 KB
testcase_05 AC 1,262 ms
288,284 KB
testcase_06 AC 1,243 ms
288,476 KB
testcase_07 AC 1,221 ms
288,444 KB
testcase_08 AC 1,222 ms
301,784 KB
testcase_09 AC 1,207 ms
301,596 KB
testcase_10 AC 1,244 ms
301,676 KB
testcase_11 AC 1,225 ms
302,392 KB
testcase_12 AC 1,233 ms
301,832 KB
testcase_13 AC 1,236 ms
302,368 KB
testcase_14 AC 1,240 ms
302,400 KB
testcase_15 AC 1,200 ms
301,888 KB
testcase_16 AC 1,228 ms
302,288 KB
testcase_17 AC 1,203 ms
301,900 KB
testcase_18 AC 1,208 ms
301,744 KB
testcase_19 AC 1,200 ms
301,660 KB
testcase_20 AC 1,233 ms
302,204 KB
testcase_21 AC 1,190 ms
301,792 KB
testcase_22 AC 1,196 ms
301,772 KB
testcase_23 AC 1,201 ms
301,572 KB
testcase_24 AC 1,193 ms
301,840 KB
testcase_25 AC 1,211 ms
301,784 KB
testcase_26 AC 1,265 ms
288,052 KB
testcase_27 AC 1,258 ms
288,808 KB
testcase_28 AC 1,265 ms
288,380 KB
testcase_29 AC 1,285 ms
321,144 KB
testcase_30 AC 414 ms
92,944 KB
testcase_31 AC 747 ms
187,392 KB
testcase_32 AC 393 ms
94,484 KB
testcase_33 AC 546 ms
115,348 KB
testcase_34 AC 886 ms
189,488 KB
testcase_35 AC 1,428 ms
290,352 KB
testcase_36 AC 1,394 ms
290,260 KB
testcase_37 AC 1,391 ms
290,192 KB
testcase_38 AC 475 ms
108,836 KB
testcase_39 AC 1,438 ms
276,544 KB
testcase_40 AC 636 ms
130,212 KB
testcase_41 AC 1,273 ms
290,648 KB
testcase_42 AC 1,443 ms
290,256 KB
testcase_43 AC 1,428 ms
290,488 KB
testcase_44 AC 1,432 ms
290,808 KB
testcase_45 TLE -
testcase_46 TLE -
testcase_47 TLE -
testcase_48 AC 1,238 ms
302,480 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) - 1;
		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];
			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