QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#780782#7954. Special NumbersNYCU_MyGO#WA 180ms9996kbC++203.6kb2024-11-25 13:11:262024-11-25 13:11:28

Judging History

你现在查看的是最新测评结果

  • [2024-11-25 13:11:28]
  • 评测
  • 测评结果:WA
  • 用时:180ms
  • 内存:9996kb
  • [2024-11-25 13:11:26]
  • 提交

answer

#ifndef MyGO
#define MyGO
#include MyGO __FILE__ MyGO

const int mod = 1'000'000'007;

void solve() {
    int K, K_tmp; cin >> K, K_tmp = K;
    string L, R; cin >> L >> R;

    int k2 = 0, k3 = 0, k5 = 0, k7 = 0;
    while (K % 2 == 0) K /= 2, ++k2;
    while (K % 3 == 0) K /= 3, ++k3;
    while (K % 5 == 0) K /= 5, ++k5;
    while (K % 7 == 0) K /= 7, ++k7;
    if (K > 1) { cout << 0 << "\n"; return; }
    K = K_tmp;

    ///            0  1  2  3  4  5  6  7  8  9 ///
    vector<int> p2{0, 0, 1, 0, 2, 0, 1, 0, 3, 0};
    vector<int> p3{0, 0, 0, 1, 0, 0, 1, 0, 0, 2};
    vector<int> p5{0, 0, 0, 0, 0, 1, 0, 0, 0, 0};
    vector<int> p7{0, 0, 0, 0, 0, 0, 0, 1, 0, 0};

    map<tuple<int, int, int, int, int, bool, bool, bool>, int> dp;
    auto _calc = [&](const string &lim, int e2, int e3, int e5, int e7, int d, bool is_cap, bool is_zero, bool is_first, auto &&self) -> int {
        if (d == SZ(lim)) return (is_zero or (e2 == k2 and e3 == k3 and e5 == k5 and e7 == k7));
        // debug(e2, e3, e5, e7, d, is_cap, is_zero, is_first);
        if (auto it = dp.find(make_tuple(e2, e3, e5, e7, d, is_cap, is_zero, is_first)); it != end(dp)) return it->second;
        int ans = 0;
        for (int v = 0; v <= (is_cap ? lim[d] - '0' : 9); ++v) {
            ans += self(
                lim,
                min(k2, e2 + p2[v]),
                min(k3, e3 + p3[v]),
                min(k5, e5 + p5[v]),
                min(k7, e7 + p7[v]),
                d + 1,
                is_cap and (v == lim[d] - '0'),
                is_zero or (not is_first and v == 0),
                is_first and (v == 0),
                self
            );
        }
        // debug(e2, e3, e5, e7, d, is_cap, is_zero, is_first, ans);
        return dp[make_tuple(e2, e3, e5, e7, d, is_cap, is_zero, is_first)] = ans % mod;
    };
    auto calc = [&](string lim) -> int {
        dp.clear();
        int tmp = _calc(lim, 0, 0, 0, 0, 0, true, false, true, _calc);
        // debug(lim, tmp);
        return tmp;
    };

    auto chk = [&](string x) -> int {
        u64 mul = 1;
        for (char c : x) mul *= (c - '0');
        return (mul % K == 0);
    };

    int ans = (calc(R) - calc(L) + chk(L) + mod) % mod;
    cout << ans << "\n";
}

int32_t main() {
    fastIO();
    
    int t = 1;
    // cin >> t;
    while (t--) solve();
}

#else

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
#define int i64
using pii = pair<int, int>;

#define ee emplace
#define eb emplace_back
#define ef emplace_front
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define SZ(x) ((int)(x).size())

template <typename T>
ostream& operator << (ostream &os, const vector<T> &vec) {
    for (int i = 0; i < SZ(vec); ++i) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}

#ifdef local
#define fastIO() void()
#define debug(...) \
    fprintf(stderr, "\u001b[33m"), \
    fprintf(stderr, "Line %d: (%s) = ", __LINE__, #__VA_ARGS__), \
    _do(__VA_ARGS__), \
    fprintf(stderr, "\u001b[0m")
template <typename T> void _do(T &&_t) { cerr << _t << "\n"; }
template <typename T, typename ...U> void _do(T &&_t, U &&..._u) { cerr << _t << ", ", _do(_u...); }
#else
#define fastIO() cin.tie(0)->sync_with_stdio(0)
#define debug(...) void()
#endif

template <typename T, typename U> bool chmin(T &lhs, U rhs) { return lhs > rhs ? lhs = rhs, 1 : 0; }
template <typename T, typename U> bool chmax(T &lhs, U rhs) { return lhs < rhs ? lhs = rhs, 1 : 0; }

#endif

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3548kb

input:

5 1 20

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

5 50 100

output:

19

result:

ok single line: '19'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

15 11 19

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

1 100 100000

output:

99901

result:

ok single line: '99901'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

1 1 1

output:

1

result:

ok single line: '1'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3728kb

input:

10 800 43021

output:

23570

result:

ok single line: '23570'

Test #7:

score: 0
Accepted
time: 1ms
memory: 3736kb

input:

1125899906842624 1 100000000000000000000

output:

555058180

result:

ok single line: '555058180'

Test #8:

score: 0
Accepted
time: 5ms
memory: 4096kb

input:

187500000 5941554024261918062 17356601866920567143

output:

679191360

result:

ok single line: '679191360'

Test #9:

score: 0
Accepted
time: 5ms
memory: 3896kb

input:

1555848 157165614890794026 49792374427566422833

output:

588832126

result:

ok single line: '588832126'

Test #10:

score: 0
Accepted
time: 102ms
memory: 7932kb

input:

53814924637488000 8378901287491856069 46225409092942057365

output:

964965504

result:

ok single line: '964965504'

Test #11:

score: 0
Accepted
time: 180ms
memory: 9996kb

input:

11814720750000000 8152927138245188051 35351923956338524619

output:

183963359

result:

ok single line: '183963359'

Test #12:

score: 0
Accepted
time: 52ms
memory: 6008kb

input:

6453888000000 4334845344448208535 35982793193772682339

output:

570114022

result:

ok single line: '570114022'

Test #13:

score: 0
Accepted
time: 75ms
memory: 6832kb

input:

90071357282285400 7893548167754114409 27099084703937108974

output:

869822186

result:

ok single line: '869822186'

Test #14:

score: 0
Accepted
time: 79ms
memory: 7596kb

input:

45571065750000 177160749596350425 98884377930460959454

output:

607698665

result:

ok single line: '607698665'

Test #15:

score: 0
Accepted
time: 40ms
memory: 5888kb

input:

1128443962982400 6338876482181492537 40931938533793596007

output:

881168270

result:

ok single line: '881168270'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

1 1 1

output:

1

result:

ok single line: '1'

Test #17:

score: 0
Accepted
time: 29ms
memory: 5148kb

input:

1412793457031250 2410155470167050095 99063185266833009818

output:

399813226

result:

ok single line: '399813226'

Test #18:

score: 0
Accepted
time: 115ms
memory: 7892kb

input:

67722117120000 8909573534349989418 73129289758235281558

output:

898227227

result:

ok single line: '898227227'

Test #19:

score: 0
Accepted
time: 35ms
memory: 5280kb

input:

472055808000 6809917603531307093 27494416416722163137

output:

379198478

result:

ok single line: '379198478'

Test #20:

score: 0
Accepted
time: 36ms
memory: 5516kb

input:

19353600000 8687492345912514346 24058039408337150852

output:

250715555

result:

ok single line: '250715555'

Test #21:

score: 0
Accepted
time: 21ms
memory: 4692kb

input:

47855420020225440 6150828649270625443 84863934988301168136

output:

665186711

result:

ok single line: '665186711'

Test #22:

score: 0
Accepted
time: 18ms
memory: 4532kb

input:

1382400000 9545797804645162278 70441077437727026904

output:

278230087

result:

ok single line: '278230087'

Test #23:

score: 0
Accepted
time: 3ms
memory: 3908kb

input:

816293376 2952089614708276156 10939708785225040670

output:

120954190

result:

ok single line: '120954190'

Test #24:

score: 0
Accepted
time: 5ms
memory: 3864kb

input:

4185097875 1348426133484952253 56617823359794500344

output:

773995224

result:

ok single line: '773995224'

Test #25:

score: 0
Accepted
time: 27ms
memory: 4872kb

input:

5828945117184 7777082394971366991 63470232991138132969

output:

678496908

result:

ok single line: '678496908'

Test #26:

score: 0
Accepted
time: 25ms
memory: 4868kb

input:

16184770560 3869053219872876321 94590086601168840932

output:

168181821

result:

ok single line: '168181821'

Test #27:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

2 1 12

output:

6

result:

ok single line: '6'

Test #28:

score: 0
Accepted
time: 5ms
memory: 4120kb

input:

30146484375 290228705524339176 51853415145287716863

output:

229436627

result:

ok single line: '229436627'

Test #29:

score: 0
Accepted
time: 52ms
memory: 6096kb

input:

2072513819443200 3726664558969607832 42501102605103061370

output:

947952932

result:

ok single line: '947952932'

Test #30:

score: 0
Accepted
time: 136ms
memory: 9248kb

input:

9920232000000000 4602219263214498291 80783137037024823899

output:

846877519

result:

ok single line: '846877519'

Test #31:

score: 0
Accepted
time: 48ms
memory: 5696kb

input:

97200000000000000 9310820760839688870 35322929083473756214

output:

936587432

result:

ok single line: '936587432'

Test #32:

score: 0
Accepted
time: 6ms
memory: 4180kb

input:

45209390625 5752361069878044328 64635325028527078951

output:

578047592

result:

ok single line: '578047592'

Test #33:

score: 0
Accepted
time: 149ms
memory: 9188kb

input:

54442233216000 2452030574225118723 90982734056131320662

output:

417646585

result:

ok single line: '417646585'

Test #34:

score: 0
Accepted
time: 36ms
memory: 5556kb

input:

1530550080000 7431421026778839808 84825282227911272129

output:

600103842

result:

ok single line: '600103842'

Test #35:

score: 0
Accepted
time: 82ms
memory: 7060kb

input:

13765147361280 4924477486471254843 10002324705150566233

output:

951883713

result:

ok single line: '951883713'

Test #36:

score: 0
Accepted
time: 54ms
memory: 6592kb

input:

59825698242187500 6303744363677706767 91410210495502213963

output:

774734375

result:

ok single line: '774734375'

Test #37:

score: 0
Accepted
time: 95ms
memory: 7560kb

input:

110658879959040 2133591391458550040 48494371567095341228

output:

103505650

result:

ok single line: '103505650'

Test #38:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

1 3 100

output:

98

result:

ok single line: '98'

Test #39:

score: 0
Accepted
time: 93ms
memory: 7500kb

input:

3160365465600 8968721517098518892 78444481529635953131

output:

364620926

result:

ok single line: '364620926'

Test #40:

score: -100
Wrong Answer
time: 0ms
memory: 3552kb

input:

54838448056132899 4242999884713464056 92948071680698209741

output:

0

result:

wrong answer 1st lines differ - expected: '922087167', found: '0'