結果

問題 No.260 世界のなんとか3
ユーザー hiyokko2hiyokko2
提出日時 2017-08-09 10:45:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 1,254 bytes
コンパイル時間 2,409 ms
コンパイル使用メモリ 147,060 KB
実行使用メモリ 26,248 KB
最終ジャッジ日時 2023-08-02 08:52:40
合計ジャッジ時間 5,135 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
26,080 KB
testcase_01 AC 10 ms
25,948 KB
testcase_02 AC 10 ms
25,980 KB
testcase_03 AC 154 ms
26,120 KB
testcase_04 AC 160 ms
26,052 KB
testcase_05 AC 38 ms
26,024 KB
testcase_06 AC 29 ms
25,920 KB
testcase_07 AC 107 ms
25,968 KB
testcase_08 AC 79 ms
25,980 KB
testcase_09 AC 48 ms
25,924 KB
testcase_10 AC 121 ms
25,988 KB
testcase_11 AC 114 ms
25,952 KB
testcase_12 AC 73 ms
25,992 KB
testcase_13 AC 28 ms
25,964 KB
testcase_14 AC 103 ms
26,120 KB
testcase_15 AC 36 ms
25,960 KB
testcase_16 AC 92 ms
25,984 KB
testcase_17 AC 75 ms
25,928 KB
testcase_18 AC 73 ms
25,912 KB
testcase_19 AC 91 ms
25,916 KB
testcase_20 AC 67 ms
25,968 KB
testcase_21 AC 61 ms
25,944 KB
testcase_22 AC 104 ms
25,948 KB
testcase_23 AC 20 ms
25,952 KB
testcase_24 AC 83 ms
25,984 KB
testcase_25 AC 104 ms
25,952 KB
testcase_26 AC 63 ms
25,980 KB
testcase_27 AC 11 ms
25,984 KB
testcase_28 AC 154 ms
26,012 KB
testcase_29 AC 195 ms
26,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;

string A, B;
int dp[30101][2][2][3][8]; //pos, less, has3, mod3, mod8

int countAho(string A)
{
    REP(i,30101) REP(j,2) REP(k,2) REP(l,3) REP(m,8) {
        dp[i][j][k][l][m] = 0;
    }

    int n = A.length();
    dp[0][0][0][0][0] = 1;
    REP(i,n) REP(j,2) REP(k,2) REP(l,3) REP(m,8) {
        int lim = j ? 9 : A[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]) %= MOD;
        }
    }

    int ans = 0;
    REP(j,2) REP(k,2) REP(l,3) REP(m,8) {
        if ((k || l == 0) && m != 0) {
            (ans += dp[n][j][k][l][m]) %= MOD;
        }
    }

    return ans;
}

signed main()
{
    cin >> A >> B;
    bool flag = false;
    int now = A.length() - 1;
    while (!flag) {
        if (A[now] != '0') {
            A[now] -= 1;
            flag = true;
        } else {
            A[now] = '9';
            now--;
        }
    }
    //cout << "A = " << A << endl;
    int ans = (countAho(B) + MOD - countAho(A)) % MOD;
    cout << ans << endl;
}
0