結果

問題 No.260 世界のなんとか3
ユーザー kimiyukikimiyuki
提出日時 2017-01-08 18:17:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 2,223 bytes
コンパイル時間 1,119 ms
コンパイル使用メモリ 79,832 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-22 17:39:54
合計ジャッジ時間 4,154 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 173 ms
4,384 KB
testcase_04 AC 173 ms
4,376 KB
testcase_05 AC 33 ms
4,380 KB
testcase_06 AC 23 ms
4,380 KB
testcase_07 AC 117 ms
4,376 KB
testcase_08 AC 82 ms
4,376 KB
testcase_09 AC 46 ms
4,376 KB
testcase_10 AC 132 ms
4,380 KB
testcase_11 AC 124 ms
4,380 KB
testcase_12 AC 75 ms
4,376 KB
testcase_13 AC 22 ms
4,380 KB
testcase_14 AC 113 ms
4,504 KB
testcase_15 AC 30 ms
4,376 KB
testcase_16 AC 98 ms
4,376 KB
testcase_17 AC 78 ms
4,380 KB
testcase_18 AC 75 ms
4,376 KB
testcase_19 AC 97 ms
4,380 KB
testcase_20 AC 69 ms
4,376 KB
testcase_21 AC 61 ms
4,384 KB
testcase_22 AC 112 ms
4,380 KB
testcase_23 AC 12 ms
4,380 KB
testcase_24 AC 86 ms
4,380 KB
testcase_25 AC 88 ms
4,380 KB
testcase_26 AC 87 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 172 ms
4,500 KB
testcase_29 AC 174 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using ll = long long;
using namespace std;
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }
// strmodin(s, a, b, m)[i][j] = the number of digits t in mod m  for  t \le s, i = t \bmod \prod a and t contains digits j \subset b
vector<vector<ll> > strmodin(string const & s, int a, vector<int> const & b, ll m) {
    int pow_b = 1 << b.size();
    array<int,10> table = {};
    repeat (d,10) {
        auto it = whole(find, b, d);
        if (it != b.end()) table[d] |= 1 << (it - b.begin());
    }
    auto cur = vectors(a, pow_b, ll());
    auto prv = vectors(a, pow_b, ll());
    int bound_i = 0, bound_j = 0;
    for (char c : s) {
        c -= '0';
        cur.swap(prv);
        repeat (d, c) cur[(bound_i * 10 + d) % a][bound_j | table[d]] += 1;
        bound_i = (bound_i * 10 + c) % a;
        bound_j |= table[c];
        repeat (i,a) repeat (j,pow_b) {
            repeat (d,10) {
                ll & it = cur[(i * 10 + d) % a][j | table[d]];
                it = (it + prv[i][j]) % m;
            }
            prv[i][j] = 0;
        }
    }
    cur[bound_i][bound_j] += 1;
    cur[bound_i][bound_j] %= m;
    return cur;
}
const int mod = 1e9+7;
ll f(string const & s) {
    auto dp = strmodin(s, 3 * 8, { 3 }, mod);
    ll cnt = 0;
    repeat (i,3*8) repeat (j,2) {
        if ((i % 3 == 0 or j) and i % 8 != 0) {
            cnt += dp[i][j];
            cnt %= mod;
        }
    }
    return cnt;
}
bool g(string const & s) {
    auto modstr = [&](ll m) {
        ll q = 0;
        for (char c : s) q = (q * 10 + (c - '0')) % m;
        return q;
    };
    return (modstr(3) == 0 or whole(count, s, '3')) and modstr(8) != 0;
}
int main() {
    string a, b; cin >> a >> b;
    cout << ((f(b) - f(a) + g(a)) % mod + mod) % mod << endl;
    return 0;
}
0