結果

問題 No.260 世界のなんとか3
ユーザー pekempeypekempey
提出日時 2015-08-01 00:45:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 1,459 bytes
コンパイル時間 1,208 ms
コンパイル使用メモリ 160,612 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-25 07:47:44
合計ジャッジ時間 3,977 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,880 KB
testcase_01 AC 7 ms
10,752 KB
testcase_02 AC 7 ms
10,880 KB
testcase_03 AC 137 ms
10,880 KB
testcase_04 AC 141 ms
11,008 KB
testcase_05 AC 31 ms
10,752 KB
testcase_06 AC 23 ms
10,880 KB
testcase_07 AC 95 ms
10,880 KB
testcase_08 AC 69 ms
10,880 KB
testcase_09 AC 42 ms
10,880 KB
testcase_10 AC 107 ms
10,880 KB
testcase_11 AC 101 ms
10,752 KB
testcase_12 AC 65 ms
10,880 KB
testcase_13 AC 22 ms
10,880 KB
testcase_14 AC 92 ms
10,752 KB
testcase_15 AC 29 ms
10,880 KB
testcase_16 AC 83 ms
11,008 KB
testcase_17 AC 66 ms
10,880 KB
testcase_18 AC 63 ms
10,880 KB
testcase_19 AC 81 ms
10,880 KB
testcase_20 AC 58 ms
11,008 KB
testcase_21 AC 54 ms
10,880 KB
testcase_22 AC 94 ms
11,008 KB
testcase_23 AC 15 ms
10,880 KB
testcase_24 AC 72 ms
11,008 KB
testcase_25 AC 92 ms
11,008 KB
testcase_26 AC 54 ms
11,008 KB
testcase_27 AC 7 ms
10,752 KB
testcase_28 AC 138 ms
10,880 KB
testcase_29 AC 176 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;

ll dp[10002][2][2][3][8]; // ind, below, use3, mod3, mod8

ll solve(string N) {
    memset(dp, 0, sizeof(dp));

    dp[0][0][0][0][0] = 1;
    rep (i, N.length()) {
        rep (j, 2) rep (k, 2) rep (l, 3) rep (m, 8) {
            int ub = j == 0 ? N[i] - '0' : 9;
            rep (n, ub + 1) {
                (dp[i + 1][j || n != ub][k || n == 3][(l + n) % 3][(n + m * 10) % 8] += dp[i][j][k][l][m]) %= mod;
            }
        }
    }

    ll ans = 0;
    rep (j, 2) rep (k, 2) rep (l, 3) rep2 (m, 1, 8) {
        if (k || l == 0) {
            (ans += dp[N.length()][j][k][l][m]) %= mod;
        }
    }
    return ans;
}

ll modulo(ll a) {
    a %= mod; a += mod; a %= mod;
    return a;
}

string decrement(string S) {
    int bollow = 1;
    repr (i, S.length()) {
        int p = S[i] - '0';
        if (p - bollow < 0) {
            S[i] = '9';
            bollow = 1;
        } else {
            S[i] = (p - bollow) + '0';
            break;
        }
    }

    return S;
}

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

    ll b = solve(B);
    ll a = solve(decrement(A));

    cout << modulo(b - a) << endl;
}
0