結果

問題 No.260 世界のなんとか3
ユーザー krotonkroton
提出日時 2015-05-31 22:37:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,011 bytes
コンパイル時間 385 ms
コンパイル使用メモリ 53,848 KB
実行使用メモリ 12,036 KB
最終ジャッジ日時 2023-08-07 13:55:53
合計ジャッジ時間 2,870 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,868 KB
testcase_01 AC 6 ms
10,772 KB
testcase_02 AC 5 ms
10,920 KB
testcase_03 AC 93 ms
11,976 KB
testcase_04 AC 92 ms
12,000 KB
testcase_05 AC 22 ms
11,320 KB
testcase_06 AC 17 ms
11,112 KB
testcase_07 AC 65 ms
11,820 KB
testcase_08 AC 47 ms
11,968 KB
testcase_09 AC 29 ms
11,364 KB
testcase_10 AC 72 ms
11,712 KB
testcase_11 AC 68 ms
11,892 KB
testcase_12 AC 43 ms
11,576 KB
testcase_13 AC 16 ms
11,064 KB
testcase_14 AC 63 ms
11,848 KB
testcase_15 AC 20 ms
11,148 KB
testcase_16 AC 55 ms
11,616 KB
testcase_17 AC 44 ms
11,528 KB
testcase_18 AC 43 ms
11,340 KB
testcase_19 AC 54 ms
11,820 KB
testcase_20 AC 40 ms
11,544 KB
testcase_21 AC 37 ms
11,568 KB
testcase_22 AC 62 ms
11,684 KB
testcase_23 AC 11 ms
11,052 KB
testcase_24 AC 49 ms
11,732 KB
testcase_25 AC 45 ms
11,968 KB
testcase_26 AC 44 ms
11,984 KB
testcase_27 AC 5 ms
10,844 KB
testcase_28 AC 81 ms
12,036 KB
testcase_29 AC 83 ms
11,960 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