結果

問題 No.315 世界のなんとか3.5
ユーザー nebukuro09nebukuro09
提出日時 2017-03-23 00:00:20
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,572 bytes
コンパイル時間 1,254 ms
コンパイル使用メモリ 147,896 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-19 05:31:47
合計ジャッジ時間 10,155 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define ll long long

const int MOD = 1000000007;
int dp[2][2][3][2][800];

int solve(string N, int P, bool less) {
    int M = N.size();
    memset(dp[0], 0, sizeof(dp[0]));
    dp[0][0][0][0][0] = 1;

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

    int ret = 0;
    REP(b, 2) {
        if (less && (b == 0)) continue;
        REP(c, 3) REP(d, 2) REP(e, P) {
            if ((c == 0 || d == 1) && e != 0) {
                ret += dp[M%2][b][c][d][e];
            }
        }
    }

    return ret;
}

int main() {
    string A, B;
    int P;
    cin >> A >> B >> P;

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

    cout << ans << endl;
}
0