結果

問題 No.528 10^9と10^9+7と回文
ユーザー nebukuro09nebukuro09
提出日時 2017-06-09 23:51:31
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,127 bytes
コンパイル時間 1,106 ms
コンパイル使用メモリ 93,976 KB
実行使用メモリ 17,116 KB
最終ジャッジ日時 2023-09-03 14:08:06
合計ジャッジ時間 2,896 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 99 ms
15,592 KB
testcase_13 AC 99 ms
17,116 KB
testcase_14 AC 62 ms
10,708 KB
testcase_15 AC 55 ms
11,116 KB
testcase_16 AC 51 ms
10,140 KB
testcase_17 AC 43 ms
7,872 KB
testcase_18 AC 94 ms
14,836 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 43 ms
7,884 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 79 ms
15,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 && k <= 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;
}
0