結果

問題 No.315 世界のなんとか3.5
ユーザー nebukuro09nebukuro09
提出日時 2017-03-22 23:24:23
言語 D
(dmd 2.105.2)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,168 bytes
コンパイル時間 668 ms
コンパイル使用メモリ 102,268 KB
実行使用メモリ 15,628 KB
最終ジャッジ日時 2023-09-03 12:33:49
合計ジャッジ時間 24,747 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
11,484 KB
testcase_01 AC 2 ms
4,868 KB
testcase_02 AC 11 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 12 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 3 ms
5,316 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 680 ms
4,380 KB
testcase_13 AC 683 ms
4,380 KB
testcase_14 AC 1,423 ms
4,376 KB
testcase_15 AC 1,406 ms
4,380 KB
testcase_16 AC 1,405 ms
4,380 KB
testcase_17 AC 1,389 ms
4,380 KB
testcase_18 AC 677 ms
4,380 KB
testcase_19 AC 675 ms
4,376 KB
testcase_20 AC 697 ms
4,376 KB
testcase_21 AC 707 ms
4,376 KB
testcase_22 AC 1,417 ms
4,380 KB
testcase_23 AC 1,413 ms
4,380 KB
testcase_24 AC 1,399 ms
4,376 KB
testcase_25 AC 1,399 ms
4,380 KB
testcase_26 AC 1,380 ms
4,376 KB
testcase_27 AC 1,407 ms
4,380 KB
testcase_28 AC 1,393 ms
4,376 KB
testcase_29 TLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

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;

immutable int MOD = 10^^9+7;

int solve(ref string N, int P, bool less) {
    auto M = N.length;
    auto dp = new int[][][][][](2, 2, 3, 2, 800);
    // 桁, N未満か, mod3, 3がつくか, mod P


    dp[0][0][0][0][0] = 1;

    foreach (a; 0..M) {
        int cur = a % 2;
        int tar = 1 - cur;
        dp[tar] = new int[][][][](2, 3, 2, 800);
        foreach (b; 0..2) {
            int digit = b ? 10 : N[a]-'0'+1;
            foreach (c; 0..3) {
                foreach (d; 0..2) {
                    if (M - a < 6) {
                        foreach (e; 0..P) {
                            foreach (f; 0..digit) {
                                dp[tar][b||(f<N[a]-'0')][(c+f)%3][d||(f==3)][(10*e+f)%P] +=
                                    dp[cur][b][c][d][e];
                                dp[tar][b||(f<N[a]-'0')][(c+f)%3][d||(f==3)][(10*e+f)%P] %= MOD;
                            }
                        }
                    }
                    else {
                        foreach (f; 0..digit) {
                            dp[tar][b||(f<N[a]-'0')][(c+f)%3][d||(f==3)][0] +=
                                dp[cur][b][c][d][0];
                            dp[tar][b||(f<N[a]-'0')][(c+f)%3][d||(f==3)][0] %= MOD;
                        }
                    }
                }
            }
        }
    }

    int ret = 0;
    foreach (a; 0..2) {
        if (less && (a == 0)) continue;
        foreach (b; 0..3) {
            foreach (c; 0..2) {
                foreach (d; 1..P) {
                    if (b == 0 || c == 1) {
                        ret += dp[M%2][a][b][c][d];
                        ret %= MOD;
                    }
                }
            }
        }
    }

    return ret;
}

void main() {
    auto s = readln.split;
    auto A = s[0];
    auto B = s[1];
    auto P = s[2].to!int;

    auto a = solve(A, P, true);
    auto b = solve(B, P, false);
    auto ans = (b - a) % MOD;
    ans = (ans + MOD) % MOD;

    ans.writeln;
}
0