結果

問題 No.260 世界のなんとか3
ユーザー hiyokko2hiyokko2
提出日時 2017-08-09 10:31:33
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,228 bytes
コンパイル時間 1,158 ms
コンパイル使用メモリ 161,436 KB
実行使用メモリ 11,140 KB
最終ジャッジ日時 2024-04-20 08:21:25
合計ジャッジ時間 3,661 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,796 KB
testcase_01 AC 5 ms
10,912 KB
testcase_02 AC 3 ms
10,996 KB
testcase_03 AC 122 ms
11,132 KB
testcase_04 AC 124 ms
11,000 KB
testcase_05 AC 27 ms
11,008 KB
testcase_06 AC 19 ms
11,016 KB
testcase_07 AC 84 ms
11,000 KB
testcase_08 AC 59 ms
10,928 KB
testcase_09 AC 36 ms
10,988 KB
testcase_10 AC 94 ms
11,012 KB
testcase_11 AC 88 ms
11,028 KB
testcase_12 AC 56 ms
11,024 KB
testcase_13 AC 18 ms
10,948 KB
testcase_14 AC 82 ms
10,788 KB
testcase_15 AC 24 ms
10,868 KB
testcase_16 AC 78 ms
11,012 KB
testcase_17 AC 64 ms
10,880 KB
testcase_18 AC 59 ms
11,096 KB
testcase_19 AC 71 ms
10,956 KB
testcase_20 WA -
testcase_21 AC 46 ms
11,060 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 81 ms
11,004 KB
testcase_26 AC 46 ms
10,996 KB
testcase_27 AC 4 ms
10,976 KB
testcase_28 WA -
testcase_29 AC 158 ms
10,856 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[10101][2][2][3][8]; //pos, less, has3, mod3, mod8

int countAho(string A)
{
    REP(i,10101) 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