結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー ks2mks2m
提出日時 2021-03-05 23:05:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 229 ms / 3,000 ms
コード長 1,376 bytes
コンパイル時間 2,026 ms
コンパイル使用メモリ 77,972 KB
実行使用メモリ 49,728 KB
最終ジャッジ日時 2024-04-16 11:04:07
合計ジャッジ時間 8,515 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
41,468 KB
testcase_01 AC 124 ms
41,112 KB
testcase_02 AC 125 ms
41,252 KB
testcase_03 AC 109 ms
41,160 KB
testcase_04 AC 123 ms
41,528 KB
testcase_05 AC 124 ms
41,192 KB
testcase_06 AC 124 ms
41,236 KB
testcase_07 AC 113 ms
40,072 KB
testcase_08 AC 127 ms
41,504 KB
testcase_09 AC 115 ms
40,296 KB
testcase_10 AC 124 ms
41,632 KB
testcase_11 AC 122 ms
41,384 KB
testcase_12 AC 126 ms
41,248 KB
testcase_13 AC 122 ms
41,652 KB
testcase_14 AC 121 ms
41,020 KB
testcase_15 AC 123 ms
41,628 KB
testcase_16 AC 124 ms
41,632 KB
testcase_17 AC 124 ms
40,944 KB
testcase_18 AC 123 ms
41,372 KB
testcase_19 AC 111 ms
41,340 KB
testcase_20 AC 122 ms
41,580 KB
testcase_21 AC 111 ms
41,396 KB
testcase_22 AC 124 ms
41,316 KB
testcase_23 AC 124 ms
41,336 KB
testcase_24 AC 126 ms
41,624 KB
testcase_25 AC 122 ms
41,232 KB
testcase_26 AC 122 ms
41,156 KB
testcase_27 AC 121 ms
41,512 KB
testcase_28 AC 126 ms
41,404 KB
testcase_29 AC 124 ms
41,540 KB
testcase_30 AC 155 ms
41,712 KB
testcase_31 AC 139 ms
42,316 KB
testcase_32 AC 163 ms
42,540 KB
testcase_33 AC 177 ms
43,168 KB
testcase_34 AC 203 ms
49,596 KB
testcase_35 AC 229 ms
49,604 KB
testcase_36 AC 210 ms
49,728 KB
testcase_37 AC 215 ms
49,376 KB
testcase_38 AC 166 ms
48,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		sc.close();

		int[] pj = {0, 0, 1, 0, 2, 0, 1, 0, 3, 0};
		int[] pk = {0, 0, 0, 0, 0, 1, 0, 0, 0, 0};
		int n = s.length;
		int mod = 1000000007;

		long[][][] dp0 = new long[n + 1][3][3];
		long[][][] dp1 = new long[n + 1][3][3];
		dp0[0][0][0] = 1;
		for (int i = 0; i < n; i++) {
			int c = s[i] - '0';
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 3; k++) {
					for (int x = 1; x < c; x++) {
						int nj = Math.min(j + pj[x], 2);
						int nk = Math.min(k + pk[x], 2);
						dp1[i + 1][nj][nk] += dp0[i][j][k];
					}
					if (c > 0) {
						int nj = Math.min(j + pj[c], 2);
						int nk = Math.min(k + pk[c], 2);
						dp0[i + 1][nj][nk] += dp0[i][j][k];
					}
				}
			}

			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 3; k++) {
					for (int x = 1; x <= 9; x++) {
						int nj = Math.min(j + pj[x], 2);
						int nk = Math.min(k + pk[x], 2);
						dp1[i + 1][nj][nk] += dp1[i][j][k];
					}
				}
			}
			dp1[i + 1][0][0] += 1;

			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 3; k++) {
					dp0[i + 1][j][k] %= mod;
					dp1[i + 1][j][k] %= mod;
				}
			}
		}
		long ans = dp0[n][2][2] + dp1[n][2][2];
		ans %= mod;
		System.out.println(ans);
	}
}
0