結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
11,136 KB
testcase_01 AC 8 ms
11,136 KB
testcase_02 AC 8 ms
11,136 KB
testcase_03 AC 75 ms
11,008 KB
testcase_04 AC 74 ms
11,136 KB
testcase_05 AC 21 ms
11,008 KB
testcase_06 AC 16 ms
11,008 KB
testcase_07 AC 53 ms
11,264 KB
testcase_08 AC 39 ms
11,008 KB
testcase_09 AC 25 ms
11,008 KB
testcase_10 AC 58 ms
11,136 KB
testcase_11 AC 55 ms
11,008 KB
testcase_12 AC 37 ms
11,136 KB
testcase_13 AC 16 ms
11,008 KB
testcase_14 AC 51 ms
11,136 KB
testcase_15 AC 20 ms
11,008 KB
testcase_16 AC 45 ms
11,008 KB
testcase_17 AC 37 ms
11,008 KB
testcase_18 AC 37 ms
11,136 KB
testcase_19 AC 44 ms
11,136 KB
testcase_20 AC 34 ms
11,136 KB
testcase_21 AC 32 ms
11,136 KB
testcase_22 AC 51 ms
11,008 KB
testcase_23 AC 12 ms
11,008 KB
testcase_24 AC 41 ms
11,136 KB
testcase_25 AC 50 ms
11,136 KB
testcase_26 AC 31 ms
11,136 KB
testcase_27 AC 8 ms
11,008 KB
testcase_28 AC 56 ms
11,008 KB
testcase_29 AC 91 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 * 10 + 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