結果
| 問題 |
No.528 10^9と10^9+7と回文
|
| ユーザー |
|
| 提出日時 | 2017-06-09 23:49:29 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,127 bytes |
| コンパイル時間 | 586 ms |
| コンパイル使用メモリ | 111,268 KB |
| 実行使用メモリ | 15,292 KB |
| 最終ジャッジ日時 | 2024-06-12 19:52:01 |
| 合計ジャッジ時間 | 2,144 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 WA * 9 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;
long solve(string N, long M) {
long ans = 0;
auto K = N.length.to!int;
auto dp = new long[][][](K/2+K%2+1, 2, 2);
dp[0][0][1] = 1;
foreach (i; 0..K/2+K%2) {
foreach (j; 0..2) {
foreach (h; 0..2) {
int d = j ? 9 : N[i] - '0';
foreach (k; 0..d+1) {
if (i == 0 && k == 0) continue;
(dp[i+1][j || (k < d)][h && d <= N[$-i-1] - '0'] += dp[i][j][h]) %= M;
}
}
}
}
foreach (j; 0..2) {
foreach (k; 0..2) {
if (j == 0 && k == 0) continue;
(ans += dp[K/2+K%2][j][k]) %= M;
}
}
long tmp = 9;
foreach (k; 1..K) {
if (k >= 3 && k % 2 == 1) tmp = tmp * 10 % M;
ans = (ans + tmp) % M;
}
return ans;
}
void main() {
auto N = readln.chomp;
solve(N, 10^^9).writeln;
solve(N, 10^^9+7).writeln;
}