結果

問題 No.1331 Moving Penguin
ユーザー ks2mks2m
提出日時 2021-01-08 22:27:14
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,201 bytes
コンパイル時間 2,136 ms
コンパイル使用メモリ 76,500 KB
実行使用メモリ 321,188 KB
最終ジャッジ日時 2024-04-28 03:51:28
合計ジャッジ時間 54,221 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
46,592 KB
testcase_01 RE -
testcase_02 AC 50 ms
36,752 KB
testcase_03 AC 50 ms
36,892 KB
testcase_04 AC 1,230 ms
289,292 KB
testcase_05 AC 1,214 ms
289,356 KB
testcase_06 AC 1,198 ms
289,084 KB
testcase_07 AC 1,178 ms
289,076 KB
testcase_08 AC 1,176 ms
301,504 KB
testcase_09 AC 1,199 ms
302,396 KB
testcase_10 AC 1,175 ms
302,260 KB
testcase_11 AC 1,210 ms
302,368 KB
testcase_12 AC 1,191 ms
301,788 KB
testcase_13 AC 1,178 ms
302,216 KB
testcase_14 AC 1,146 ms
301,676 KB
testcase_15 AC 1,170 ms
301,720 KB
testcase_16 AC 1,194 ms
302,180 KB
testcase_17 AC 1,165 ms
301,740 KB
testcase_18 AC 1,167 ms
301,552 KB
testcase_19 AC 1,193 ms
302,348 KB
testcase_20 AC 1,131 ms
301,500 KB
testcase_21 AC 1,166 ms
302,228 KB
testcase_22 AC 1,152 ms
301,684 KB
testcase_23 AC 1,171 ms
301,800 KB
testcase_24 AC 1,168 ms
302,420 KB
testcase_25 AC 1,180 ms
302,408 KB
testcase_26 AC 1,173 ms
288,880 KB
testcase_27 AC 1,172 ms
289,132 KB
testcase_28 AC 1,177 ms
289,684 KB
testcase_29 AC 1,210 ms
321,188 KB
testcase_30 AC 433 ms
93,564 KB
testcase_31 AC 719 ms
187,480 KB
testcase_32 AC 373 ms
94,556 KB
testcase_33 AC 500 ms
115,584 KB
testcase_34 AC 851 ms
189,412 KB
testcase_35 AC 1,256 ms
290,432 KB
testcase_36 AC 1,281 ms
290,356 KB
testcase_37 AC 1,269 ms
290,396 KB
testcase_38 AC 433 ms
108,192 KB
testcase_39 AC 1,285 ms
277,448 KB
testcase_40 AC 584 ms
130,480 KB
testcase_41 AC 1,157 ms
290,320 KB
testcase_42 AC 1,315 ms
290,424 KB
testcase_43 AC 1,311 ms
290,624 KB
testcase_44 AC 1,389 ms
290,616 KB
testcase_45 AC 1,452 ms
290,480 KB
testcase_46 AC 1,484 ms
290,848 KB
testcase_47 AC 1,418 ms
290,668 KB
testcase_48 AC 1,174 ms
301,612 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][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