結果

問題 No.1964 sum = length
ユーザー tentententen
提出日時 2023-01-18 10:45:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 2,207 bytes
コンパイル時間 2,615 ms
コンパイル使用メモリ 84,560 KB
実行使用メモリ 52,380 KB
最終ジャッジ日時 2023-09-02 06:34:31
合計ジャッジ時間 8,780 ms
ジャッジサーバーID
(参考情報)
judge15 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,512 KB
testcase_01 AC 41 ms
49,488 KB
testcase_02 AC 43 ms
49,420 KB
testcase_03 AC 41 ms
49,436 KB
testcase_04 AC 41 ms
49,496 KB
testcase_05 AC 43 ms
49,500 KB
testcase_06 AC 42 ms
49,552 KB
testcase_07 AC 41 ms
49,636 KB
testcase_08 AC 42 ms
49,488 KB
testcase_09 AC 41 ms
49,428 KB
testcase_10 AC 41 ms
49,516 KB
testcase_11 AC 41 ms
49,524 KB
testcase_12 AC 48 ms
49,448 KB
testcase_13 AC 68 ms
51,704 KB
testcase_14 AC 69 ms
51,844 KB
testcase_15 AC 72 ms
51,836 KB
testcase_16 AC 42 ms
49,440 KB
testcase_17 AC 67 ms
51,712 KB
testcase_18 AC 59 ms
51,648 KB
testcase_19 AC 46 ms
49,552 KB
testcase_20 AC 46 ms
49,492 KB
testcase_21 AC 42 ms
49,588 KB
testcase_22 AC 106 ms
52,188 KB
testcase_23 AC 103 ms
52,048 KB
testcase_24 AC 82 ms
52,184 KB
testcase_25 AC 88 ms
52,380 KB
testcase_26 AC 110 ms
52,032 KB
testcase_27 AC 91 ms
51,980 KB
testcase_28 AC 88 ms
52,324 KB
testcase_29 AC 101 ms
51,848 KB
testcase_30 AC 84 ms
52,040 KB
testcase_31 AC 110 ms
52,376 KB
testcase_32 AC 75 ms
51,752 KB
testcase_33 AC 74 ms
51,988 KB
testcase_34 AC 101 ms
51,800 KB
testcase_35 AC 86 ms
52,264 KB
testcase_36 AC 93 ms
52,060 KB
testcase_37 AC 103 ms
52,104 KB
testcase_38 AC 112 ms
52,008 KB
testcase_39 AC 89 ms
52,288 KB
testcase_40 AC 94 ms
52,100 KB
testcase_41 AC 103 ms
51,940 KB
testcase_42 AC 114 ms
51,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static int[][] dp;
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        dp = new int[n][n];
        System.out.println(dfw(n - 1, n - 1));
    }
    
    static int dfw(int idx, int size) {
        if (size < 0) {
            return 0;
        }
        if (size == 0) {
            return 1;
        }
        if (idx < 0) {
            return 0;
        }
        if (dp[idx][size] == 0) {
            for (int i = 1; i <= size + 3; i++) {
                dp[idx][size] += dfw(idx - 1, size - i + getSize(i));
                dp[idx][size] %= MOD;
            }
        }
        return dp[idx][size];
    }
    
    static int getSize(int x) {
        int size = 0;
        while (x > 0) {
            size++;
            x /= 10;
        }
        return size;
    }
}

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();
    }
    
}
0