結果

問題 No.1620 Substring Sum
ユーザー yangxiaozhuoyangxiaozhuo
提出日時 2023-01-24 13:16:14
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,079 bytes
コンパイル時間 2,424 ms
コンパイル使用メモリ 74,624 KB
実行使用メモリ 49,240 KB
最終ジャッジ日時 2023-09-08 09:16:03
合計ジャッジ時間 6,860 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,084 KB
testcase_01 AC 43 ms
49,040 KB
testcase_02 AC 41 ms
49,240 KB
testcase_03 AC 42 ms
49,144 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;

/**
 * @author yangxiaozhuo
 * @date 2023/01/20
 */
public class Main {
    static int mod = 998244353;
    static long[] dp = new long[100010];

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s = in.readLine();
        dp[0] = 1;
        dp[1] = 2;
        int len = s.length();
//        8691461
//        9的贡献度,往前有2个数,有三次9
//        往后有90 * 4 + 900 * 6 + 9000 * 4 + 90000*1
//        自己有一个9
        long res = 0;
        for (int i = 0; i < len; i++) {
            long temp = 0;
            //往前,前面有i个数字  假设前面有8个数,提供次数 C0 C1 C2 C3 C4 C5 C6 C7 C8 = 2^8
            long mi = firstMi(i);
            long index = 1;
            int num = s.charAt(i) - '0';
            int otherLen = len - i - 1;
            for (int j = i; j < len; j++) {
                temp = temp + num * index * C(otherLen, j - i);
                index = (index * 10) % mod;
            }
            res = (res + mi * temp) % mod;
        }
        System.out.println(res);
    }

    private static long C(int otherLen, int m) {
        if (m == 0) {
            return 1;
        }
        if (m == 1) {
            return otherLen;
        }
        if (otherLen - m < m) {
            return C(otherLen, otherLen - m);
        }
        long temp = 1;
        for (int i = 0; i < m; i++) {
            temp = temp * (otherLen - i);
            temp = temp / (i + 1);
        }
        return temp;
    }

    private static long firstMi(int n) {
        if (dp[n] != 0) {
            return dp[n];
        }
        if (n % 2 == 0) {
            long temp = firstMi(n / 2);
            dp[n] = (temp * temp) % mod;
        } else {
            long temp = firstMi(n / 2);
            dp[n] = (temp * temp * 2) % mod;
        }
        return dp[n];
    }
}
0