結果

問題 No.260 世界のなんとか3
ユーザー noynotenoynote
提出日時 2017-08-28 17:05:39
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 1,126 bytes
コンパイル時間 1,834 ms
コンパイル使用メモリ 197,108 KB
実行使用メモリ 11,256 KB
最終ジャッジ日時 2024-04-24 01:52:57
合計ジャッジ時間 4,670 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,124 KB
testcase_01 AC 4 ms
11,116 KB
testcase_02 AC 4 ms
11,004 KB
testcase_03 AC 148 ms
11,104 KB
testcase_04 AC 148 ms
11,052 KB
testcase_05 AC 32 ms
10,964 KB
testcase_06 AC 24 ms
10,932 KB
testcase_07 AC 108 ms
11,004 KB
testcase_08 AC 75 ms
11,072 KB
testcase_09 AC 40 ms
11,092 KB
testcase_10 AC 113 ms
11,120 KB
testcase_11 AC 105 ms
11,092 KB
testcase_12 AC 67 ms
11,056 KB
testcase_13 AC 21 ms
11,256 KB
testcase_14 AC 95 ms
11,012 KB
testcase_15 AC 27 ms
11,136 KB
testcase_16 AC 83 ms
11,140 KB
testcase_17 AC 68 ms
10,968 KB
testcase_18 AC 66 ms
10,996 KB
testcase_19 AC 82 ms
11,068 KB
testcase_20 AC 61 ms
11,104 KB
testcase_21 AC 55 ms
10,988 KB
testcase_22 AC 98 ms
10,972 KB
testcase_23 AC 14 ms
11,152 KB
testcase_24 AC 75 ms
10,960 KB
testcase_25 AC 96 ms
10,948 KB
testcase_26 AC 56 ms
11,032 KB
testcase_27 AC 5 ms
10,992 KB
testcase_28 AC 106 ms
10,988 KB
testcase_29 AC 185 ms
11,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
const long long M = 1000000007;
using namespace std;

long long dp[10005][2][2][3][8] = {0}; //i文字まで見た、sより小さい、3が含まれる、mod 3, mod8

long long solve(string s, bool f){
    assert(s.size() < 10005);
    memset(dp, 0, sizeof(dp));
    dp[0][0][0][0][0] = 1;

    rep(i,s.size()) rep(j,2) rep(k,2) rep(l,3) rep(m,8) {
        int lim = j ? 9 : s[i] - '0';
        rep(d,lim + 1){
            (dp[i + 1][j || d < lim][k || (d == 3)][(l + d) % 3][(m * 10 + d) % 8] += dp[i][j][k][l][m]) %= M;
        }
    }

    long long ans = 0, less = 0;
    rep(j,2) rep(k,3) rep(l,8) if((j || k == 0) && l != 0){
        (ans += dp[s.size()][1][j][k][l]) %= M;
        (less += dp[s.size()][0][j][k][l]) %= M;
    }

    return (ans + (f ? 0 : less) + M) % M;

}

int main(){
    string a, b;
    cin >> a >> b;

    cout << (solve(b,0) - solve(a,1) + M) % M << endl;
}
0