結果

問題 No.260 世界のなんとか3
ユーザー fushime2fushime2
提出日時 2017-04-05 14:20:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 1,361 bytes
コンパイル時間 2,342 ms
コンパイル使用メモリ 149,420 KB
実行使用メモリ 11,216 KB
最終ジャッジ日時 2023-09-22 19:59:12
合計ジャッジ時間 5,646 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,872 KB
testcase_01 AC 6 ms
10,928 KB
testcase_02 AC 6 ms
10,996 KB
testcase_03 AC 148 ms
11,208 KB
testcase_04 AC 149 ms
10,976 KB
testcase_05 AC 32 ms
10,916 KB
testcase_06 AC 24 ms
10,936 KB
testcase_07 AC 103 ms
11,132 KB
testcase_08 AC 73 ms
11,004 KB
testcase_09 AC 43 ms
11,048 KB
testcase_10 AC 115 ms
10,916 KB
testcase_11 AC 108 ms
11,052 KB
testcase_12 AC 67 ms
10,996 KB
testcase_13 AC 23 ms
10,960 KB
testcase_14 AC 99 ms
11,004 KB
testcase_15 AC 31 ms
10,908 KB
testcase_16 AC 87 ms
11,192 KB
testcase_17 AC 69 ms
10,860 KB
testcase_18 AC 67 ms
10,960 KB
testcase_19 AC 85 ms
11,216 KB
testcase_20 AC 63 ms
10,972 KB
testcase_21 AC 56 ms
11,008 KB
testcase_22 AC 98 ms
10,960 KB
testcase_23 AC 14 ms
10,816 KB
testcase_24 AC 78 ms
11,092 KB
testcase_25 AC 98 ms
11,072 KB
testcase_26 AC 57 ms
11,028 KB
testcase_27 AC 5 ms
10,972 KB
testcase_28 AC 149 ms
11,052 KB
testcase_29 AC 191 ms
11,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) FOR(i,0,n)
#define mset(a,x) memset(a,x,sizeof(a))
#define SZ(x) (int)(x).size()

ll dp[10010][2][2][3][8];
const int MOD = int(1e9) + 7;

ll calc(string s) {
    vector<int> ds;
    for(char& c : s) ds.push_back(c - '0');
    const int N = ds.size();

    mset(dp, 0);
    dp[0][0][0][0][0] = 1;
    rep(i, N) rep(j, 2) {
        int lim = 9;
        if(j == 0) lim = ds[i];
        rep(k, 2) rep(m3, 3) rep(m8, 8) {
            rep(d, lim + 1) {
                (dp[i + 1][j || d < lim][k || d == 3][(m3 + d) % 3][(m8 * 10 + d) % 8] += dp[i][j][k][m3][m8]) %= MOD;
            }
        }
    }

    ll ret = 0;
    rep(j, 2) rep(k, 2) rep(m3, 3) rep(m8, 8) {
        if((k || m3 == 0) && m8 != 0) {
            ret += dp[N][j][k][m3][m8];
            ret %= MOD;
        }
    }
    return ret;
}

string dec(string s) {
    int add = 1;
    for(int i = SZ(s) - 1; i >= 0; i--) {
        int p = s[i] - '0';
        if(p - add < 0) {
            s[i] = '9';
            add = 1;
        }
        else {
            s[i] = (p - add) + '0';
            break;
        }
    }
    return s;
}

int main() {
    string a, b;
    cin >> a >> b;
    cout << ((calc(b) - calc(dec(a))) % MOD + MOD) % MOD << endl;

    return 0;
}
0