結果

問題 No.260 世界のなんとか3
ユーザー fushime2fushime2
提出日時 2017-04-05 13:25:31
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,066 bytes
コンパイル時間 1,200 ms
コンパイル使用メモリ 149,004 KB
実行使用メモリ 89,720 KB
最終ジャッジ日時 2023-09-22 19:46:36
合計ジャッジ時間 5,509 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 MLE -
testcase_02 MLE -
testcase_03 MLE -
testcase_04 MLE -
testcase_05 MLE -
testcase_06 MLE -
testcase_07 MLE -
testcase_08 MLE -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 MLE -
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
testcase_26 MLE -
testcase_27 MLE -
testcase_28 MLE -
testcase_29 MLE -
権限があれば一括ダウンロードができます

ソースコード

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))

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

ll calc(string s, bool less) {
    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(less && j == 0) continue;
        if((k || m3 == 0) && m8 != 0) {
            ret += dp[N][j][k][m3][m8];
            ret %= MOD;
        }
    }
    return ret;
}


int main() {
    string a, b;
    cin >> a >> b;
    cout << calc(b, 0) - calc(a, 1) << endl;

    return 0;
}
0