結果

問題 No.260 世界のなんとか3
ユーザー fushime2fushime2
提出日時 2017-04-05 13:29:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,065 bytes
コンパイル時間 1,144 ms
コンパイル使用メモリ 148,868 KB
実行使用メモリ 11,336 KB
最終ジャッジ日時 2023-09-22 19:46:47
合計ジャッジ時間 4,401 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,168 KB
testcase_01 AC 6 ms
11,184 KB
testcase_02 AC 6 ms
11,132 KB
testcase_03 WA -
testcase_04 AC 149 ms
11,012 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 43 ms
10,976 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 67 ms
11,212 KB
testcase_13 WA -
testcase_14 AC 98 ms
11,184 KB
testcase_15 AC 31 ms
10,876 KB
testcase_16 AC 87 ms
11,000 KB
testcase_17 WA -
testcase_18 AC 68 ms
10,916 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 77 ms
10,996 KB
testcase_25 AC 98 ms
11,120 KB
testcase_26 AC 57 ms
11,172 KB
testcase_27 AC 6 ms
10,852 KB
testcase_28 AC 107 ms
11,064 KB
testcase_29 AC 190 ms
11,332 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))

ll dp[10010][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