結果

問題 No.260 世界のなんとか3
ユーザー krotonkroton
提出日時 2015-05-31 22:37:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 1,011 bytes
コンパイル時間 483 ms
コンパイル使用メモリ 57,260 KB
実行使用メモリ 12,128 KB
最終ジャッジ日時 2024-04-25 07:39:25
合計ジャッジ時間 2,567 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,988 KB
testcase_01 AC 6 ms
11,008 KB
testcase_02 AC 6 ms
10,736 KB
testcase_03 AC 88 ms
11,904 KB
testcase_04 AC 86 ms
11,984 KB
testcase_05 AC 21 ms
11,124 KB
testcase_06 AC 17 ms
11,136 KB
testcase_07 AC 63 ms
11,648 KB
testcase_08 AC 48 ms
11,776 KB
testcase_09 AC 29 ms
11,392 KB
testcase_10 AC 69 ms
11,648 KB
testcase_11 AC 63 ms
11,904 KB
testcase_12 AC 41 ms
11,520 KB
testcase_13 AC 16 ms
10,868 KB
testcase_14 AC 56 ms
11,776 KB
testcase_15 AC 21 ms
11,136 KB
testcase_16 AC 53 ms
11,632 KB
testcase_17 AC 42 ms
11,516 KB
testcase_18 AC 41 ms
11,332 KB
testcase_19 AC 53 ms
11,896 KB
testcase_20 AC 38 ms
11,520 KB
testcase_21 AC 35 ms
11,520 KB
testcase_22 AC 61 ms
11,648 KB
testcase_23 AC 11 ms
10,880 KB
testcase_24 AC 47 ms
11,776 KB
testcase_25 AC 41 ms
12,032 KB
testcase_26 AC 41 ms
12,032 KB
testcase_27 AC 4 ms
10,880 KB
testcase_28 AC 76 ms
12,032 KB
testcase_29 AC 77 ms
12,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string.h>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7;

ll dp[10010][2][24][2];
ll func(const string&S, bool last, int k, bool less, int mod, bool used3) {
    if(k >= S.size()) {
        if(!less && !last)return 0;
        bool aho = (mod % 3 == 0) || used3;
        bool sei = (mod % 8 == 0);
        return aho && !sei;
    }
    if(dp[k][less][mod][used3] != -1)return dp[k][less][mod][used3];

    ll res = 0;
    int d = S[k] - '0';
    for(int i=0;i<10;i++) {
        if(i <= d || less) {
            res += func(S, last, k + 1, less || (i < d), (mod * 10 + i) % 24, used3 || (i == 3));
        }
    }

    res %= MOD;
    return dp[k][less][mod][used3] = res;
}

ll solve(const string& S, bool last) {
    memset(dp, -1, sizeof(dp));
    return func(S, last, 0, false, 0, false);
}

int main(){
    string A, B;
    cin >> A >> B;

    ll res = solve(B, true) - solve(A, false);
    res = (res + MOD) % MOD;

    cout << res << endl;
    return 0;
}
0