結果
| 問題 |
No.1620 Substring Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-01-24 13:16:14 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,079 bytes |
| コンパイル時間 | 2,383 ms |
| コンパイル使用メモリ | 77,116 KB |
| 実行使用メモリ | 61,096 KB |
| 最終ジャッジ日時 | 2024-06-26 02:20:30 |
| 合計ジャッジ時間 | 5,990 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 2 |
| other | AC * 4 TLE * 1 -- * 15 |
ソースコード
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];
}
}