結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
46,612 KB
testcase_01 AC 51 ms
36,848 KB
testcase_02 AC 54 ms
36,784 KB
testcase_03 AC 53 ms
36,576 KB
testcase_04 AC 1,268 ms
289,232 KB
testcase_05 AC 1,237 ms
289,244 KB
testcase_06 AC 1,235 ms
289,136 KB
testcase_07 AC 1,239 ms
289,320 KB
testcase_08 AC 1,246 ms
302,380 KB
testcase_09 AC 1,233 ms
302,336 KB
testcase_10 AC 1,208 ms
301,412 KB
testcase_11 AC 1,196 ms
301,888 KB
testcase_12 AC 1,206 ms
301,920 KB
testcase_13 AC 1,239 ms
302,360 KB
testcase_14 AC 1,246 ms
302,448 KB
testcase_15 AC 1,238 ms
302,872 KB
testcase_16 AC 1,247 ms
301,608 KB
testcase_17 AC 1,252 ms
302,420 KB
testcase_18 AC 1,249 ms
302,240 KB
testcase_19 AC 1,204 ms
301,828 KB
testcase_20 AC 1,244 ms
302,144 KB
testcase_21 AC 1,245 ms
302,372 KB
testcase_22 AC 1,245 ms
302,340 KB
testcase_23 AC 1,202 ms
301,576 KB
testcase_24 AC 1,198 ms
301,608 KB
testcase_25 AC 1,235 ms
302,392 KB
testcase_26 AC 1,261 ms
289,568 KB
testcase_27 AC 1,267 ms
289,668 KB
testcase_28 AC 1,275 ms
288,836 KB
testcase_29 AC 1,294 ms
321,372 KB
testcase_30 AC 450 ms
92,912 KB
testcase_31 AC 775 ms
187,604 KB
testcase_32 AC 371 ms
94,284 KB
testcase_33 AC 543 ms
115,544 KB
testcase_34 AC 875 ms
189,388 KB
testcase_35 AC 1,290 ms
290,580 KB
testcase_36 AC 1,286 ms
290,384 KB
testcase_37 AC 1,279 ms
290,604 KB
testcase_38 AC 448 ms
108,576 KB
testcase_39 AC 1,388 ms
277,576 KB
testcase_40 AC 630 ms
130,416 KB
testcase_41 AC 1,270 ms
290,272 KB
testcase_42 AC 1,296 ms
290,312 KB
testcase_43 AC 1,280 ms
290,588 KB
testcase_44 AC 1,308 ms
290,252 KB
testcase_45 AC 1,383 ms
290,824 KB
testcase_46 TLE -
testcase_47 TLE -
testcase_48 AC 1,187 ms
301,892 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);
		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