結果

問題 No.260 世界のなんとか3
ユーザー fushime2fushime2
提出日時 2017-04-05 14:19:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,347 bytes
コンパイル時間 1,211 ms
コンパイル使用メモリ 149,496 KB
実行使用メモリ 11,208 KB
最終ジャッジ日時 2023-09-22 19:58:22
合計ジャッジ時間 4,565 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,812 KB
testcase_01 AC 5 ms
11,040 KB
testcase_02 AC 6 ms
10,908 KB
testcase_03 WA -
testcase_04 AC 149 ms
11,064 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 43 ms
10,920 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 67 ms
10,956 KB
testcase_13 WA -
testcase_14 AC 98 ms
10,964 KB
testcase_15 AC 30 ms
10,896 KB
testcase_16 AC 87 ms
10,944 KB
testcase_17 WA -
testcase_18 AC 67 ms
10,952 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 77 ms
10,896 KB
testcase_25 AC 99 ms
11,008 KB
testcase_26 AC 57 ms
10,968 KB
testcase_27 AC 6 ms
11,036 KB
testcase_28 AC 148 ms
11,092 KB
testcase_29 AC 190 ms
11,016 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 << endl;

    return 0;
}
0