結果

問題 No.528 10^9と10^9+7と回文
ユーザー nebukuro09nebukuro09
提出日時 2017-06-10 00:19:58
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,093 bytes
コンパイル時間 673 ms
コンパイル使用メモリ 94,072 KB
実行使用メモリ 6,888 KB
最終ジャッジ日時 2023-09-03 14:08:31
合計ジャッジ時間 2,658 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,384 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 54 ms
6,660 KB
testcase_11 AC 55 ms
5,320 KB
testcase_12 WA -
testcase_13 AC 54 ms
5,904 KB
testcase_14 WA -
testcase_15 AC 30 ms
6,888 KB
testcase_16 WA -
testcase_17 AC 23 ms
5,880 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 38 ms
4,460 KB
testcase_21 AC 22 ms
4,556 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 7 ms
4,380 KB
testcase_26 WA -
testcase_27 AC 43 ms
5,860 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);
    dp[0][0] = 1;

    foreach (i; 0..K/2+K%2) {
        foreach (j; 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 < N[i] - '0')] += dp[i][j]) %= M;
            }
        }
    }

    foreach (j; 0..2) {
        (ans += dp[K/2+K%2][j]) %= M;
    }

    string NN = "";
    foreach (i; 0..N.length) if (i <= K / 2 + K % 2) NN ~= N[i]; else NN ~= N[$-i-1];
    if (NN > N) ans = (ans - 1 + M) % 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