QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#345090#7954. Special Numbersjuancs#WA 0ms3864kbC++204.3kb2024-03-06 04:52:352024-03-06 04:52:35

Judging History

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

  • [2024-03-06 04:52:35]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3864kb
  • [2024-03-06 04:52:35]
  • 提交

answer

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define el '\n'
#define pb push_back
#define forn(i, n) for(int i = 0; i < (int)n; ++i)
#define for1(i, n) for(int i = 1; i <= (int)n; ++i)
#define fore(i,l,r ) for(int i = l; i<= r; ++i)
#define ford(i, n) for(int i = (int)n - 1; i >= 0; --i)
#define sz(a) (int) a.size()
#define fi first
#define se second
#define d(x) cerr << #x << ' ' << x << el
#define all(x) x.begin(), x.end()
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef __int128_t i128;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef array<int, 7> a7;

const int mod = 1e9 + 7;

struct mint{
    int x;
    mint(): x(0){}
    mint(int x): x(x){}
    mint operator+(mint b){
        int ans = x + b.x;
        if(ans >= mod)ans -= mod;
        return mint(ans);
    }
    mint operator-(mint b){
        int ans = x - b.x;
        if(ans < 0)ans += mod;
        return mint(ans);
    }
    mint operator*(mint b){
        return 1LL*x*b.x%mod;
    }
};

int cnts[4];
int trans[10][4];
map<a7, mint> dp;
string l, r, cr, cstr;

mint go(a7 st){
    if(st[0] == sz(cr)){
        if(st[2] == 1)return 0; 
        forn(i, 4){
            if(st[i + 3] != cnts[i])return 0;
        }
        // d(st[0]);
        // d(st[1]);
        // d(st[2]);
        // forn(i, 4)cout << st[i + 3] << ' ';
        // cout << el;
        // cout << cstr << el;
        return 1;
    }
    if(dp.count(st))return dp[st];
    mint& ans = dp[st];
    ans = 0;
    int e = !st[1] ? 9 : cr[st[0]] - '0';
    if(st[2]){
        a7 cur = st;
        ++cur[0];
        cur[1] = false;
        ans = ans + go(cur);
    }
    for1(i, e){
        a7 cur = st;
        ++cur[0];
        cur[1] = st[1] && i == e;
        cur[2] = false;
        forn(j, 4){
            cur[j + 3] += trans[i][j];
            cur[j + 3] = min(cur[j + 3], cnts[j]);
        }
        cstr.pb(i + '0');
        // d(i);
        ans = ans + go(cur);
        cstr.pop_back();
    }
    return ans;
}

mint binpow(mint b, int e){
    mint ans = 1;
    for(; e; b = b * b, e /= 2){
        if(e&1)ans = ans * b;
    }
    return ans;
}

mint inv(mint x){
    return binpow(x, mod - 2);
}

mint cnt(){
    mint ans = 0;
    mint iten = inv(10);
    mint inine = inv(9);
    forn(i, sz(cr)){
        mint pt = binpow(10, sz(cr) - i - 1);
        mint pn = binpow(9, sz(cr) - i - 1);
        if(i != 0){
            ans = ans + (mint(9)*(pt - pn));
            pt = pt * iten;
            pn = pn * inine;
            continue;
        }
        fore(j, i, sz(cr) - 1){
            if(cr[j] == '0'){
                if(cr[i] == '0')break;
                mint num = 0;
                fore(k, j + 1, sz(cr) - 1){
                    num = num + (pt*mint(cr[k] - '0'));
                    pt = pt * iten;
                }
                ans = ans + num + 1;
                break;
            }
            mint dj = cr[j] - '1';
            ans = ans + (dj*(pt - pn));
            pt = pt * iten;
            pn = pn * inine;
        }
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int k;
    cin >> k >> l >> r;
    vector<int> primes = {2, 3, 5, 7};
    int tk = k;
    forn(i, 4){
        int& p = primes[i];
        while(tk % p == 0){
            ++cnts[i];
            tk /=p;
        }
    }
    if(tk != 1){
        cout << 0 << el;
        return 0;
    }
    for1(i, 9){
        int ti = i;
        forn(j, 4){
            int& p = primes[j];
            while(ti % p == 0){
                trans[i][j]++;
                ti /= p;
            }
        }
    }
    cr = r;
    a7 st = {0, 1, 1, 0, 0, 0, 0,};
    mint rans = go(st);
    rans = rans + cnt();
    dp.clear();
    cr = l;
    // cout << "####" << el;
    mint lans = go(st);
    lans = lans + cnt();
    // d(rans.x);
    // d(lans.x);
    i128 cl = 0;
    i128 pt = 1;
    ford(i, sz(l)){
        char& c  = l[i];
        cl += (c - '0')*pt;
        pt *= i128(10);
    }
    // d(ll(cl));
    mint ans = rans - (lans - mint(cl % k == 0));
    cout << ans.x << el;
}

详细

Test #1:

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

input:

5 1 20

output:

4

result:

ok single line: '4'

Test #2:

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

input:

5 50 100

output:

19

result:

ok single line: '19'

Test #3:

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

input:

15 11 19

output:

0

result:

ok single line: '0'

Test #4:

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

input:

1 100 100000

output:

99901

result:

ok single line: '99901'

Test #5:

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

input:

1 1 1

output:

1

result:

ok single line: '1'

Test #6:

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

input:

10 800 43021

output:

22759

result:

wrong answer 1st lines differ - expected: '23570', found: '22759'