結果

問題 No.315 世界のなんとか3.5
ユーザー kimiyukikimiyuki
提出日時 2017-01-08 21:02:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 712 ms / 2,000 ms
コード長 2,233 bytes
コンパイル時間 885 ms
コンパイル使用メモリ 81,348 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 17:49:12
合計ジャッジ時間 11,671 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 178 ms
4,376 KB
testcase_13 AC 178 ms
4,376 KB
testcase_14 AC 356 ms
4,380 KB
testcase_15 AC 357 ms
4,376 KB
testcase_16 AC 358 ms
4,380 KB
testcase_17 AC 357 ms
4,380 KB
testcase_18 AC 180 ms
4,380 KB
testcase_19 AC 180 ms
4,380 KB
testcase_20 AC 180 ms
4,380 KB
testcase_21 AC 180 ms
4,376 KB
testcase_22 AC 357 ms
4,380 KB
testcase_23 AC 356 ms
4,380 KB
testcase_24 AC 357 ms
4,380 KB
testcase_25 AC 358 ms
4,380 KB
testcase_26 AC 358 ms
4,376 KB
testcase_27 AC 359 ms
4,380 KB
testcase_28 AC 357 ms
4,376 KB
testcase_29 AC 708 ms
4,380 KB
testcase_30 AC 709 ms
4,380 KB
testcase_31 AC 708 ms
4,376 KB
testcase_32 AC 712 ms
4,380 KB
testcase_33 AC 359 ms
4,376 KB
testcase_34 AC 703 ms
4,376 KB
testcase_35 AC 710 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#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); }
const int mod = 1e9+7;
ll f(string const & s, int p) {
    ll cnt = 0;
    auto cur = vectors(3*8, 2, ll());
    auto prv = vectors(3*8, 2, ll());
    int bound_i = 0, bound_j = 0;
    repeat (ix, s.length()) {
        char c = s[ix] - '0';
        cur.swap(prv);
        repeat (d, c) cur[(bound_i * 10 + d) % (3*8)][bound_j or d == 3] += 1;
        bound_i = (bound_i * 10 + c) % (3*8);
        if (c == 3) bound_j = true;
        repeat (i,3*8) repeat (j,2) {
            repeat (d,10) {
                ll & it = cur[(i * 10 + d) % (3*8)][j or d == 3];
                it = (it + prv[i][j]) % mod;
            }
            prv[i][j] = 0;
        }
        if ((p == 8 and ix+1 == s.length()) or (p == 80 and ix+2 == s.length()) or (p == 800 and ix+3 == s.length())) {
            if ((bound_i % 3 == 0 or bound_j) and bound_i % 8 == 0) {
                cnt -= 1;
            }
            repeat (i,3*8) repeat (j,2) {
                if ((i % 3 == 0 or j) and i % 8 == 0) {
                    cnt -= cur[i][j];
                }
            }
        }
    }
    cur[bound_i][bound_j] += 1;
    cur[bound_i][bound_j] %= mod;
    repeat (i,3*8) repeat (j,2) {
        if (i % 3 == 0 or j) {
            cnt += cur[i][j];
            cnt %= mod;
        }
    }
    return cnt;
}
bool g(string const & s, int p) {
    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(p) != 0;
}
int main() {
    string a, b; int p; cin >> a >> b >> p;
    cout << ((f(b, p) - f(a, p) + g(a, p)) % mod + mod) % mod << endl;
    return 0;
}
0