結果

問題 No.315 世界のなんとか3.5
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-04-25 00:53:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,619 bytes
コンパイル時間 1,659 ms
コンパイル使用メモリ 168,124 KB
実行使用メモリ 8,700 KB
最終ジャッジ日時 2023-10-11 13:36:24
合計ジャッジ時間 6,743 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,700 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 4 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 4 ms
4,352 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 4 ms
4,352 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 4 ms
4,352 KB
testcase_12 TLE -
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 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)



int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
template<class... T> int add(int x, T... y) { return add(x, add(y...)); }
int mul(int x, int y) { return 1LL * x * y % mod; }
template<class... T> int mul(int x, T... y) { return mul(x, mul(y...)); }
int sub(int x, int y) { return add(x, mod - y); }
int modpow(int a, long long b) { int ret = 1; while (b > 0) { if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1; } return ret; }
int modinv(int a) { return modpow(a, mod - 2); }

int fac[201010], ifac[201010];
void initfac() {
    fac[0] = ifac[0] = 1;
    rep(i, 1, 201010) fac[i] = 1LL * i * fac[i - 1] % mod;
    rep(i, 1, 201010) ifac[i] = modinv(fac[i]);
}
int aCb(int a, int b) {
    if (b < 0 || a < b) return 0;
    return (1LL * fac[a] * ifac[a - b] % mod) * ifac[b] % mod;
}
//-----------------------------------------------------------------------------------
int P;
int dp[2][2400][2][2];
int count(string S) {
    int n = S.length();
    rep(i, 0, 2) rep(j, 0, 2400) rep(k, 0, 2) rep(l, 0, 2) dp[i][j][k][l] = 0;

    dp[0][0][0][1] = 1;
    rep(_i, 0, n) {
        int i = _i % 2, ii = (_i + 1) % 2;
        int cc = S[_i] - '0';
        rep(j, 0, 2400) rep(k, 0, 2) rep(l, 0, 2) dp[ii][j][k][l] = 0;
        rep(j, 0, 2400) rep(k, 0, 2) rep(l, 0, 2) {
            int ma = 10;
            if (l == 1) ma = cc + 1;
            rep(c, 0, ma) {
                int jj = (j * 10 + c) % 2400;
                int kk = k | (c == 3);
                int ll;

                if (l == 1 && c == cc) ll = 1;
                else ll = 0;

                dp[ii][jj][kk][ll] = add(dp[ii][jj][kk][ll], dp[i][j][k][l]);
            }
        }
    }

    int res = 0;
    int nn = n % 2;
    rep(j, 0, 2400) rep(l, 0, 2) if (j % P != 0) {
        res = add(res, dp[nn][j][1][l]);
    }
    rep(j, 0, 2400) rep(l, 0, 2) if (j % 3 == 0 && j % P != 0) {
        res = add(res, dp[nn][j][0][l]);
    }
    return res;
}
//-----------------------------------------------------------------------------------
bool chk(string S) {
    int mo = 0;
    for (char c : S) mo = (mo * 10 + c - '0') % 2400;

    bool aho = (mo % 3 == 0);
    for (char c : S) if (c == '3') aho = true;

    bool seishun = (mo % P == 0);

    return aho && !seishun;
}
//-----------------------------------------------------------------------------------
int main() {
    string A, B; cin >> A >> B >> P;

    int ans = sub(count(B), count(A));
    if (chk(A)) ans = add(ans, 1);
    cout << ans << endl;
}
0