結果

問題 No.528 10^9と10^9+7と回文
ユーザー nebukuro09nebukuro09
提出日時 2017-06-09 23:13:18
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,181 bytes
コンパイル時間 849 ms
コンパイル使用メモリ 94,036 KB
実行使用メモリ 5,196 KB
最終ジャッジ日時 2023-09-03 14:07:21
合計ジャッジ時間 5,837 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

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 KK = N.length.to!int;

    for (int K = N.to!string.length.to!int; K > 0; K--) {
        auto dp = new long[][][](K/2+K%2+1, 2, 2);
        dp[0][0][0] = 1;
        foreach (i; 0..K/2+K%2) {
            foreach (j; 0..2) {
                foreach (h; 0..2) {
                    int d = K == KK ? N[i+KK-K] - '0' : 9;
                    foreach (k; 0..d+1) {
                        if (i == 0 && k == 0) continue;
                        (dp[i+1][j || (k < d)][(K != KK) || (h && d <= N[$-i-1] - '0')] += dp[i][j][h]) %= M;
                    }
                }
            }
        }

        foreach (j; 0..2) {
            foreach (k; 0..2) {
                if (K == KK && k == 0) continue;
                (ans += dp[K/2+K%2][j][k]) %= M;
            }
        }
        //ans.writeln;
    }

    return ans;
}


void main() {
    auto N = readln.chomp;
    solve(N, 10^^9).writeln;
    solve(N, 10^^9+7).writeln;
}
0