QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#125266#6741. Digitheno239AC ✓647ms20448kbC++177.9kb2023-07-16 14:04:522023-07-16 14:04:55

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-16 14:04:55]
  • 评测
  • 测评结果:AC
  • 用时:647ms
  • 内存:20448kb
  • [2023-07-16 14:04:52]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
#include<chrono>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
//ll mod = 1;
constexpr ll mod = 998244353;
//constexpr ll mod = 1000000007;
const int mod17 = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;

#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;

using ld = long double;
typedef pair<ld, ld> LDP;
const ld eps = 1e-10;
const ld pi = acosl(-1.0);

template<typename T>
void chmin(T& a, T b) {
    a = min(a, b);
}
template<typename T>
void chmax(T& a, T b) {
    a = max(a, b);
}
template<typename T>
vector<T> vmerge(vector<T>& a, vector<T>& b) {
    vector<T> res;
    int ida = 0, idb = 0;
    while (ida < a.size() || idb < b.size()) {
        if (idb == b.size()) {
            res.push_back(a[ida]); ida++;
        }
        else if (ida == a.size()) {
            res.push_back(b[idb]); idb++;
        }
        else {
            if (a[ida] < b[idb]) {
                res.push_back(a[ida]); ida++;
            }
            else {
                res.push_back(b[idb]); idb++;
            }
        }
    }
    return res;
}
template<typename T>
void cinarray(vector<T>& v) {
    rep(i, v.size())cin >> v[i];
}
template<typename T>
void coutarray(vector<T>& v) {
    rep(i, v.size()) {
        if (i > 0)cout << " "; cout << v[i];
    }
    cout << "\n";
}
ll mod_pow(ll x, ll n, ll m = mod) {
    if (n < 0) {
        ll res = mod_pow(x, -n, m);
        return mod_pow(res, m - 2, m);
    }
    if (abs(x) >= m)x %= m;
    if (x < 0)x += m;
    //if (x == 0)return 0;
    ll res = 1;
    while (n) {
        if (n & 1)res = res * x % m;
        x = x * x % m; n >>= 1;
    }
    return res;
}
//mod should be <2^31
struct modint {
    int n;
    modint() :n(0) { ; }
    modint(ll m) {
        if (m < 0 || mod <= m) {
            m %= mod; if (m < 0)m += mod;
        }
        n = m;
    }
    operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
bool operator<(modint a, modint b) { return a.n < b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= (int)mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += (int)mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
    if (n == 0)return modint(1);
    modint res = (a * a) ^ (n / 2);
    if (n % 2)res = res * a;
    return res;
}

ll inv(ll a, ll p) {
    return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
    fact[0] = modint(1);
    for (int i = 0; i < max_n - 1; i++) {
        fact[i + 1] = fact[i] * modint(i + 1);
    }
    factinv[max_n - 1] = modint(1) / fact[max_n - 1];
    for (int i = max_n - 2; i >= 0; i--) {
        factinv[i] = factinv[i + 1] * modint(i + 1);
    }
}
modint comb(int a, int b) {
    if (a < 0 || b < 0 || a < b)return 0;
    return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
    if (a < 0 || b < 0 || a < b)return 0;
    return fact[a] * factinv[a - b];
}

ll gcd(ll a, ll b) {
    a = abs(a); b = abs(b);
    if (a < b)swap(a, b);
    while (b) {
        ll r = a % b; a = b; b = r;
    }
    return a;
}
template<typename T>
void addv(vector<T>& v, int loc, T val) {
    if (loc >= v.size())v.resize(loc + 1, 0);
    v[loc] += val;
}
/*const int mn = 2000005;
bool isp[mn];
vector<int> ps;
void init() {
    fill(isp + 2, isp + mn, true);
    for (int i = 2; i < mn; i++) {
        if (!isp[i])continue;
        ps.push_back(i);
        for (int j = 2 * i; j < mn; j += i) {
            isp[j] = false;
        }
    }
}*/

//[,val)
template<typename T>
auto prev_itr(set<T>& st, T val) {
    auto res = st.lower_bound(val);
    if (res == st.begin())return st.end();
    res--; return res;
}

//[val,)
template<typename T>
auto next_itr(set<T>& st, T val) {
    auto res = st.lower_bound(val);
    return res;
}
using mP = pair<modint, modint>;
mP operator+(mP a, mP b) {
    return { a.first + b.first,a.second + b.second };
}
mP operator+=(mP& a, mP b) {
    a = a + b; return a;
}
mP operator-(mP a, mP b) {
    return { a.first - b.first,a.second - b.second };
}
mP operator-=(mP& a, mP b) {
    a = a - b; return a;
}
LP operator+(LP a, LP b) {
    return { a.first + b.first,a.second + b.second };
}
LP operator+=(LP& a, LP b) {
    a = a + b; return a;
}
LP operator-(LP a, LP b) {
    return { a.first - b.first,a.second - b.second };
}
LP operator-=(LP& a, LP b) {
    a = a - b; return a;
}

mt19937 mt(time(0));

const string drul = "DRUL";
string senw = "SENW";
//DRUL,or SENW
//int dx[4] = { 1,0,-1,0 };
//int dy[4] = { 0,1,0,-1 };

//-----------------------------------------

const ll sup = 2 * INF;

modint rev[22];
vector<ll> vs;
vector<vector<int>> tos;

vector<modint> dp;
void init() {
    rep1(i, 21)rev[i] = (modint)1 / (modint)i;

    set<ll> st;
    st.insert(1);
    queue<ll> que;
    que.push(1);
    vector<int> cs = { 2,3,5,7 };
    while (!que.empty()) {
        ll v = que.front(); que.pop();
        vs.push_back(v);
        for (ll c : cs) {
            if (sup / v < c) {

            }
            else {
                ll nv = v * c;
                if (!st.count(nv)) {
                    st.insert(nv);
                    que.push(nv);
                }
            }
        }
    }
    sort(all(vs));
    //cout << vs.size() << "\n";
    tos.resize(vs.size(), vector<int>(10));
    rep(i, vs.size()) {

        ll v = vs[i];
        rep(j, 10) {
            if (sup / v < j + 1) {
                tos[i][j] = -1;
            }
            else {
                ll nv = v * (j + 1);
                int loc = lower_bound(all(vs), nv) - vs.begin();
                tos[i][j] = loc;
            }
        }
    }
    dp.resize(vs.size());
}
void solve() {
    ll n, s; cin >> n >> s;
    per(i, dp.size()) {
        if (s / n < vs[i]) {
            dp[i] = 0;
        }
        else {
            int c0 = 0;
            int cnt = 0;
            modint sum = 0;
            ll cop = n * vs[i];
            while (cop > 0) {
                cnt++;
                int r = cop % 10; cop /= 10;
                if (r == 0) {
                    c0++;
                }
                else {
                    sum += dp[tos[i][r]];
                }
            }
            sum += cnt;
            dp[i] = sum * rev[cnt - c0];
        }
    }
    cout << dp[0] << "\n";

}





signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed<<setprecision(10);
    //init_f();
    init();
    //while(true)
    //expr();
    int t; cin >> t; rep(i, t)
        solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 73ms
memory: 20336kb

input:

3
1 10
1 100
1 1000

output:

3
4
942786340

result:

ok 3 number(s): "3 4 942786340"

Test #2:

score: 0
Accepted
time: 325ms
memory: 20440kb

input:

200
6093 473302679260560320
8548 407261659389622784
643 187875386337017408
8115 804844129595563776
3331 457909423622471360
8554 769878068775393152
2189 248771553604839360
7395 486014798136226944
8022 834223266052054400
9218 291007794161740672
8431 738787973811775616
1829 183591119896739584
816 23406...

output:

401752224
25564055
349247348
24571488
454552241
293307892
841921314
316896313
340265070
679232017
880794571
220757927
783764236
593413719
368463075
771186516
780654585
3628414
827863355
617858224
868927625
446978548
351494058
130284374
125073939
38120850
748432314
277667083
183850680
235708406
51111...

result:

ok 200 numbers

Test #3:

score: 0
Accepted
time: 114ms
memory: 20364kb

input:

200
3043059018339257 22277869996577613
9995869516 503712331451
389592 72563932968
3520234478258 476959582208156
77586585 711120211545804458
77846354 2243822883730937
9937954107 8390895135555
39032 603567
7739 4682236745217490
12277973519 7136059697857236
7264388 607094625
66205992799 4030219735546
3...

output:

108920162
651706276
549514920
440563412
796578996
851857830
191543780
540715694
549223125
380090491
553492005
247956062
582309209
67430878
174114881
1
669072219
981051601
561639793
304668111
397423058
607062211
8458982
479445466
287831358
913943402
533482140
801644611
519995972
239199505
587671914
2...

result:

ok 200 numbers

Test #4:

score: 0
Accepted
time: 492ms
memory: 20320kb

input:

200
58 999999999999997440
75 999999999999999872
52 999999999999997696
85 999999999999999360
12 999999999999999488
77 999999999999999232
80 999999999999999232
36 999999999999997184
51 999999999999998720
79 999999999999997440
76 999999999999998592
90 999999999999997696
32 999999999999998336
67 9999999...

output:

603520497
574767370
222266238
241598642
627473669
958322466
776467011
836867165
317725053
772230956
80008248
170
205889745
956913345
252066713
183389093
251365357
387390363
836867165
660512518
265265911
574767370
317725053
620530996
15655429
247241569
103698881
940321220
960908253
960908253
66051251...

result:

ok 200 numbers

Test #5:

score: 0
Accepted
time: 209ms
memory: 20352kb

input:

200
509411 999999999999999232
33801448 999999999999998720
65 999999999999998208
6 999999999999997184
404287 999999999999999360
800418816395 999999999999999232
44589090134507 999999999999997312
2008080 999999999999999360
13 999999999999998976
87 999999999999999872
206327851576605 999999999999999744
3...

output:

883813861
221710219
620530996
252066714
168038945
932330901
77414612
443356611
1883978
608670663
568648025
891202485
151357997
793825022
180372901
749235099
391331669
890726608
103698881
258627374
738512765
18273750
771644777
916674174
110687232
890972839
85823452
799141196
739829892
675630993
44879...

result:

ok 200 numbers

Test #6:

score: 0
Accepted
time: 647ms
memory: 20448kb

input:

200
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 10000000...

output:

252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
...

result:

ok 200 numbers