QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#672229#7954. Special Numbersucup-team3519#WA 2ms3808kbC++172.5kb2024-10-24 16:04:252024-10-24 16:04:26

Judging History

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

  • [2024-10-24 16:04:26]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3808kb
  • [2024-10-24 16:04:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef __int128_t LLL;
#define V vector
#define pb push_back
typedef unsigned long long ULL;
typedef long long LL;
#define lb lower_bound
#define all0(x) (x).begin(), (x).end()
#define all1(x) (x).begin() + 1, (x).end()

const int mod = 1e9 + 7;
LL MOD(LL x) {
    if(x >= mod) x -= mod;
    if(x < 0) x += mod;
    return x;
}
LL upd(LL k, LL now) {
    if(now == 0) return 1;
    if(now == 4) {
        if(k % 4 == 0) return k / 4;
        if(k % 2 == 0) return k / 2;
        return k;
    }
    if(now == 9) {
        if(k % 9 == 0) return k / 9;
        if(k % 4 == 0) return k / 3;
        return k;
    }
    if(now == 8) {
        if(k % 8 == 0) return k / 8;
        if(k % 4 == 0) return k / 4;
        if(k % 2 == 0) return k / 2;
        return k;
    }
    if(now == 6) {
        if(k % 6 == 0) return k / 6;
        if(k % 2 == 0) return k / 2;
        if(k % 3 == 0) return k / 3;
        return k;
    }
    if(k % now == 0) return k / now;
    return k;
}
map<pair<int, LL>, LL> mp;
LL dfs(int now, LL res) {
    if(now == 0) {
        if(res == 1) return 1;
        return 0;
    }
    if(mp.count({now, res})) return mp[{now, res}];
    LL ans = 0;
    for(int i = 0; i <= 9; i++) {
        LL n_res = upd(res, i);
        ans = MOD(ans + dfs(now - 1, n_res));
    }
    return mp[{now, res}] = ans;
}
LL cal(string s, LL k) {
    reverse(all0(s));
    LL ans = 0;
    for(int i = s.size() - 1; i >= 1; i--) {
        for(int j = 1; j <= 9; j++) {
            LL res = upd(k, j);
            ans = MOD(ans + dfs(i - 1, res));
        }
    }
    // cout << "ans : " << ans << endl;
    for(int i = s.size() - 1; i >= 0; i--) {
        for(int j = (i == s.size() - 1 ? 1 : 0); j < s[i] - '0'; j++) {
            ans = MOD(ans + dfs(i, upd(k, j)));
        }
        k = upd(k, s[i] - '0');
    }
    // if(k == 1) {
    //     cout << "good" << endl;
    // }
    ans += k == 1;
    return ans;
}

bool is_ok(string s, LL k) {
    for(auto c : s) {
        k = upd(k, c - '0');
    }
    return k == 1;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    LL k; cin >> k;
    string l, r; cin >> l >> r;
    LL ans = MOD(cal(r, k) - cal(l, k) + is_ok(l, k));
    cout << ans << endl;
    // for(int i = 1; i <= 20; i++) {
    //     cout << "i : " << i << " " << cal(to_string(i), 5) << endl;
    // }
    // for(int i = 0; i <= 9; i++) cout << "upd, i : " << i << " " << upd(5, i) << endl;
}
//5, 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 1 20

output:

4

result:

ok single line: '4'

Test #2:

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

input:

5 50 100

output:

19

result:

ok single line: '19'

Test #3:

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

input:

15 11 19

output:

0

result:

ok single line: '0'

Test #4:

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

input:

1 100 100000

output:

99901

result:

ok single line: '99901'

Test #5:

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

input:

1 1 1

output:

1

result:

ok single line: '1'

Test #6:

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

input:

10 800 43021

output:

23570

result:

ok single line: '23570'

Test #7:

score: -100
Wrong Answer
time: 2ms
memory: 3684kb

input:

1125899906842624 1 100000000000000000000

output:

571397028

result:

wrong answer 1st lines differ - expected: '555058180', found: '571397028'