結果

問題 No.260 世界のなんとか3
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-04-25 00:33:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 2,428 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 167,408 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2023-10-11 13:35:15
合計ジャッジ時間 4,115 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 51 ms
7,624 KB
testcase_04 AC 50 ms
7,544 KB
testcase_05 AC 11 ms
4,780 KB
testcase_06 AC 8 ms
4,524 KB
testcase_07 AC 35 ms
7,592 KB
testcase_08 AC 26 ms
7,476 KB
testcase_09 AC 15 ms
5,004 KB
testcase_10 AC 40 ms
7,524 KB
testcase_11 AC 37 ms
7,460 KB
testcase_12 AC 23 ms
7,576 KB
testcase_13 AC 8 ms
4,368 KB
testcase_14 AC 34 ms
7,808 KB
testcase_15 AC 10 ms
4,372 KB
testcase_16 AC 30 ms
7,516 KB
testcase_17 AC 24 ms
5,304 KB
testcase_18 AC 23 ms
5,068 KB
testcase_19 AC 30 ms
7,444 KB
testcase_20 AC 21 ms
5,360 KB
testcase_21 AC 20 ms
7,492 KB
testcase_22 AC 34 ms
7,596 KB
testcase_23 AC 5 ms
4,368 KB
testcase_24 AC 27 ms
7,444 KB
testcase_25 AC 33 ms
7,524 KB
testcase_26 AC 20 ms
7,520 KB
testcase_27 AC 1 ms
4,372 KB
testcase_28 AC 38 ms
7,680 KB
testcase_29 AC 62 ms
7,544 KB
権限があれば一括ダウンロードができます

ソースコード

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 dp[10101][24][2][2];
int count(string S) {
    int n = S.length();
    rep(i, 0, n + 1) rep(j, 0, 24) rep(k, 0, 2) rep(l, 0, 2) dp[i][j][k][l] = 0;

    dp[0][0][0][1] = 1;
    rep(i, 0, n) rep(j, 0, 24) rep(k, 0, 2) rep(l, 0, 2){
        int cc = S[i] - '0';

        int ma = 10;
        if (l == 1) ma = cc + 1;
        rep(c, 0, ma) {
            int ii = i + 1;
            int jj = (j * 10 + c) % 24;
            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;
    rep(j, 0, 24) rep(l, 0, 2) if(j % 8 != 0){
        res = add(res, dp[n][j][1][l]);
    }
    rep(j, 0, 24) rep(l, 0, 2) if (j % 3 == 0 && j % 8 != 0) {
        res = add(res, dp[n][j][0][l]);
    }
    return res;
}
//-----------------------------------------------------------------------------------
bool chk(string S) {
    int mo = 0;
    for (char c : S) mo = (mo * 10 + c - '0') % 24;

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

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

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

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