結果

問題 No.260 世界のなんとか3
ユーザー tsutajtsutaj
提出日時 2017-07-14 09:33:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 1,224 bytes
コンパイル時間 1,576 ms
コンパイル使用メモリ 165,636 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-16 19:24:10
合計ジャッジ時間 3,898 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,008 KB
testcase_01 AC 5 ms
11,008 KB
testcase_02 AC 6 ms
10,928 KB
testcase_03 AC 71 ms
11,004 KB
testcase_04 AC 71 ms
11,064 KB
testcase_05 AC 19 ms
11,008 KB
testcase_06 AC 14 ms
11,008 KB
testcase_07 AC 50 ms
11,008 KB
testcase_08 AC 37 ms
11,124 KB
testcase_09 AC 23 ms
11,136 KB
testcase_10 AC 57 ms
11,008 KB
testcase_11 AC 52 ms
11,264 KB
testcase_12 AC 34 ms
11,136 KB
testcase_13 AC 14 ms
11,160 KB
testcase_14 AC 48 ms
11,056 KB
testcase_15 AC 17 ms
11,136 KB
testcase_16 AC 41 ms
11,144 KB
testcase_17 AC 34 ms
11,264 KB
testcase_18 AC 35 ms
11,264 KB
testcase_19 AC 43 ms
10,972 KB
testcase_20 AC 33 ms
10,956 KB
testcase_21 AC 28 ms
11,136 KB
testcase_22 AC 46 ms
11,232 KB
testcase_23 AC 10 ms
11,144 KB
testcase_24 AC 38 ms
11,136 KB
testcase_25 AC 46 ms
11,264 KB
testcase_26 AC 29 ms
11,092 KB
testcase_27 AC 6 ms
10,920 KB
testcase_28 AC 52 ms
11,136 KB
testcase_29 AC 86 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
typedef long long int ll;
typedef pair<int, int> pii;
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
constexpr ll MOD = 1000000007LL;

// digit, mod3, has3, mod8, flag
ll dp[10010][3][2][8][2];

ll solve(string s, int less) {
    memset(dp, 0, sizeof(dp));
    dp[0][0][0][0][0] = 1;
    
    int N = s.length();
    rep(i,0,N) rep(j,0,3) rep(k,0,2) rep(l,0,8) rep(f,0,2) {
        int lim = f ? 9 : s[i] - '0';
        rep(x,0,lim + 1) {
            int mo3 = (j + x) % 3;
            int mo8 = (l * 10 + x) % 8;
            (dp[i+1][mo3][k || x == 3][mo8][f || x < lim] += dp[i][j][k][l][f]) %= MOD;
        }
    }

    ll ret = 0;
    rep(j,0,3) rep(k,0,2) rep(l,0,8) rep(f,0,2) {
        if(less == 1 && f == 0) continue;
        if((j == 0 || k == 1) && l != 0) (ret += dp[N][j][k][l][f]) %= MOD;
    }
    return ret;
}

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

    ll ra = solve(A, 1), rb = solve(B, 0);
    cout << (rb - ra + MOD) % MOD << endl;
    return 0;
}
0