結果

問題 No.260 世界のなんとか3
ユーザー hiyokko2hiyokko2
提出日時 2017-08-09 10:40:05
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,228 bytes
コンパイル時間 2,329 ms
コンパイル使用メモリ 160,520 KB
実行使用メモリ 26,112 KB
最終ジャッジ日時 2024-04-20 08:23:36
合計ジャッジ時間 4,989 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
25,856 KB
testcase_01 AC 13 ms
25,984 KB
testcase_02 AC 13 ms
25,856 KB
testcase_03 AC 151 ms
25,900 KB
testcase_04 AC 151 ms
26,064 KB
testcase_05 AC 39 ms
25,984 KB
testcase_06 AC 30 ms
25,984 KB
testcase_07 AC 105 ms
26,112 KB
testcase_08 AC 76 ms
25,856 KB
testcase_09 AC 49 ms
26,084 KB
testcase_10 AC 118 ms
26,060 KB
testcase_11 AC 111 ms
26,028 KB
testcase_12 AC 72 ms
25,984 KB
testcase_13 AC 29 ms
25,976 KB
testcase_14 AC 101 ms
25,984 KB
testcase_15 AC 37 ms
26,060 KB
testcase_16 AC 93 ms
26,056 KB
testcase_17 AC 74 ms
26,112 KB
testcase_18 AC 71 ms
25,984 KB
testcase_19 AC 90 ms
25,984 KB
testcase_20 WA -
testcase_21 AC 62 ms
26,020 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 101 ms
26,104 KB
testcase_26 AC 63 ms
26,112 KB
testcase_27 AC 13 ms
25,856 KB
testcase_28 WA -
testcase_29 AC 190 ms
25,928 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 {
            now--;
        }
    }
    //cout << "A = " << A << endl;
    int ans = (countAho(B) + MOD - countAho(A)) % MOD;
    cout << ans << endl;
}
0