結果
問題 | No.2302 Carry X Times |
ユーザー | tenten |
提出日時 | 2023-05-29 13:24:41 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 100 ms / 2,000 ms |
コード長 | 4,171 bytes |
コンパイル時間 | 2,348 ms |
コンパイル使用メモリ | 89,088 KB |
実行使用メモリ | 39,220 KB |
最終ジャッジ日時 | 2024-06-08 19:12:47 |
合計ジャッジ時間 | 5,367 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 84 ms
38,772 KB |
testcase_01 | AC | 82 ms
38,912 KB |
testcase_02 | AC | 85 ms
38,788 KB |
testcase_03 | AC | 49 ms
36,976 KB |
testcase_04 | AC | 49 ms
36,864 KB |
testcase_05 | AC | 49 ms
37,020 KB |
testcase_06 | AC | 49 ms
37,172 KB |
testcase_07 | AC | 51 ms
36,800 KB |
testcase_08 | AC | 51 ms
37,128 KB |
testcase_09 | AC | 48 ms
36,960 KB |
testcase_10 | AC | 94 ms
38,880 KB |
testcase_11 | AC | 95 ms
38,584 KB |
testcase_12 | AC | 88 ms
39,028 KB |
testcase_13 | AC | 91 ms
39,056 KB |
testcase_14 | AC | 95 ms
38,768 KB |
testcase_15 | AC | 87 ms
38,836 KB |
testcase_16 | AC | 96 ms
39,020 KB |
testcase_17 | AC | 97 ms
39,192 KB |
testcase_18 | AC | 93 ms
39,096 KB |
testcase_19 | AC | 80 ms
39,160 KB |
testcase_20 | AC | 85 ms
39,220 KB |
testcase_21 | AC | 95 ms
39,168 KB |
testcase_22 | AC | 93 ms
39,072 KB |
testcase_23 | AC | 100 ms
39,176 KB |
testcase_24 | AC | 96 ms
39,068 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static int[][][][][] dp; static char[] inputs; static final int MOD = 998244353; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int t = sc.nextInt(); StringBuilder sb = new StringBuilder(); while (t-- > 0) { inputs = sc.next().toCharArray(); int x = sc.nextInt(); dp = new int[inputs.length][2][2][][]; int[][] ans = dfw(0, 0, 0); sb.append((ans[0][x] + ans[1][x]) % MOD).append("\n"); } System.out.print(sb); } static int[][] dfw(int idx, int aType, int bType) { if (dp[idx][aType][bType] == null) { int[][] ans = new int[2][20]; int aMax; if (aType == 1) { aMax = 9; } else { aMax = inputs[idx] - '0'; } int bMax; if (bType == 1) { bMax = 9; } else { bMax = inputs[idx] - '0'; } if (idx == inputs.length - 1) { for (int a = 0; a <= aMax; a++) { for (int b = 0; b <= bMax; b++) { if (a + b >= 10) { ans[1][1]++; } else { ans[0][0]++; } } } } else { for (int a = 0; a <= aMax; a++) { for (int b = 0; b <= bMax; b++) { int[][] prev; if (aType == 0 && a == aMax) { if (bType == 0 && b == bMax) { prev = dfw(idx + 1, 0, 0); } else { prev = dfw(idx + 1, 0, 1); } } else { if (bType == 0 && b == bMax) { prev = dfw(idx + 1, 1, 0); } else { prev = dfw(idx + 1, 1, 1); } } for (int i = 0; i < 19; i++) { for (int j = 0; j < 2; j++) { if (a + b + j >= 10) { ans[1][i + 1] += prev[j][i]; ans[1][i + 1] %= MOD; } else { ans[0][i] += prev[j][i]; ans[0][i] %= MOD; } } } } } } dp[idx][aType][bType] = ans; } return dp[idx][aType][bType]; } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }