結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー ks2mks2m
提出日時 2021-03-05 22:47:08
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,348 bytes
コンパイル時間 2,279 ms
コンパイル使用メモリ 77,240 KB
実行使用メモリ 49,592 KB
最終ジャッジ日時 2024-04-16 10:34:50
合計ジャッジ時間 9,445 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
40,920 KB
testcase_01 AC 138 ms
41,160 KB
testcase_02 AC 136 ms
41,312 KB
testcase_03 AC 135 ms
41,072 KB
testcase_04 AC 134 ms
41,124 KB
testcase_05 AC 145 ms
41,048 KB
testcase_06 AC 141 ms
41,300 KB
testcase_07 AC 133 ms
41,276 KB
testcase_08 AC 129 ms
41,000 KB
testcase_09 AC 134 ms
40,992 KB
testcase_10 AC 132 ms
41,284 KB
testcase_11 AC 132 ms
40,948 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 135 ms
40,984 KB
testcase_15 WA -
testcase_16 AC 136 ms
41,188 KB
testcase_17 AC 133 ms
41,296 KB
testcase_18 AC 138 ms
41,164 KB
testcase_19 WA -
testcase_20 AC 134 ms
41,324 KB
testcase_21 WA -
testcase_22 AC 133 ms
40,956 KB
testcase_23 AC 136 ms
41,356 KB
testcase_24 AC 133 ms
41,216 KB
testcase_25 AC 135 ms
41,064 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 134 ms
41,324 KB
testcase_29 AC 138 ms
41,412 KB
testcase_30 AC 168 ms
41,508 KB
testcase_31 AC 168 ms
42,024 KB
testcase_32 AC 176 ms
42,120 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 235 ms
49,396 KB
testcase_38 AC 226 ms
49,592 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];
					}
					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