QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#398569#7996. 报数 IVDopplerXDTL 877ms74492kbC++201.6kb2024-04-25 15:13:542024-04-25 15:13:56

Judging History

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

  • [2024-04-25 15:13:56]
  • 评测
  • 测评结果:TL
  • 用时:877ms
  • 内存:74492kb
  • [2024-04-25 15:13:54]
  • 提交

answer

// https://qoj.ac/contest/1464/problem/7996
// 1次f最大达到9000(sum 10^1000-1)
// 2次f最大达到35(sum 8999)
// 3次f最大达到11(sum 29)
// 4次f最大达到9(sum 9)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;
const int M = 9e3 + 5;
const int N = 1e3 + 5;
ll dp[N][M], mp[M];
string str;
int k, m, n;
int SUM(int x) {
    int res = 0;
    while (x) {
        res += (x % 10);
        x /= 10;
    }
    return res;
}
ll dfs(int p, int s, bool reach_up) { // p for position, s for sum
    // reach_up for str[p-1] have reached upper limit or not
    if (p == n) return mp[s];
    if (p > n) return 0;
    if (!reach_up && dp[p][s] != -1) return dp[p][s];
    ll res = 0;
    for (int i = 0; i <= 9; i++) {
        if (reach_up && str[p] - '0' < i) continue;
        res += dfs(p + 1, s + i, reach_up & (str[p] - '0' == i));
        res %= mod;
    }
    if (!reach_up) dp[p][s] = res;
    return res;
}
void solve() {
    cin >> str >> k >> m;
    if ((m > 9000) || (k >= 2 && m >= 35)) {
        cout << 0 << '\n';
        return;
    }
    n = str.length();
    for (int i = 1; i <= 9000; i++) {
        int x = i;
        for (int i = 1; i < k; i++) {
            x = SUM(x);
            if (x < 10) break;
        }
        if (x == m) mp[i] = 1;
        else mp[i] = 0;
    }
    memset(dp, -1, sizeof(dp));
    cout << dfs(0, 0, 1) << '\n';
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T;
    cin >> T;
    while (T--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 74352kb

input:

2
114 1 5
514 2 10

output:

8
10

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 32ms
memory: 74432kb

input:

5
114 1 5
514 2 10
114514 3 7
1919810 2 13
1145141919810114514191981011451419198101145141919810114514191981011451419198101145141919810114514191981011451419198101145141919810 1 79

output:

8
10
12724
504
481046284

result:

ok 5 lines

Test #3:

score: 0
Accepted
time: 867ms
memory: 74432kb

input:

5
3134666912140933323880320519044791121794814671711104987304374190280064994554822259889216567113228716903875026053927191961850586115167336109747673868148288830282192461669674173201533887392623483710043038941036243583011049049915834937139438028987629569618561762595613799223807979488245056374812076511...

output:

0
613343513
0
500149787
932367667

result:

ok 5 lines

Test #4:

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

input:

5
1139519997005658838804233882542131329603951012645222504700958241682545257324091070752720569220022637054777343187779232016568942045167801853025395316038491270541841827939668031807503056209394655628349207403327386083909984082879989255237547274110143051980886947606735206241362546384481120301780245959...

output:

0
0
983106233
842410978
351127737

result:

ok 5 lines

Test #5:

score: 0
Accepted
time: 877ms
memory: 74484kb

input:

5
8638076091316635855641492966551052879887835736093039980247820372626975300011595185556660107638347885877620156412525017113706895612406460047827904025826640853053762221239009476530804397983925491363476392003741370633988524528072186299564325622601218035310613510134479162974878452692502169127286160440...

output:

0
151494485
491996396
951216080
735591005

result:

ok 5 lines

Test #6:

score: 0
Accepted
time: 868ms
memory: 74436kb

input:

5
4594403190887655851098979323885347301970260472182981436563110607463337770897498592230279433635011809482497666151819612860549852933087582131069399973150048275594755688227873941703801791577493672811179138154635173296855021815570777969295164438906410283251071005981539590431740858876880832337309525533...

output:

452162993
993032288
529250142
0
0

result:

ok 5 lines

Test #7:

score: 0
Accepted
time: 642ms
memory: 74488kb

input:

5
7106329661074460076851813089444392472728206874451143771638786962963099120130351553150316525985245033972323999641553983578568333846746709032264525531367915930983812069660457027974526824268427908058438462283103774963889147187903776098321357665707620452891363086885353145154955480116362167820560099473...

output:

0
42143665
0
0
266635325

result:

ok 5 lines

Test #8:

score: 0
Accepted
time: 867ms
memory: 74492kb

input:

5
3197096843267069616758413776891049764649182364659681310636123435063129351340319661216252795154685419993835505771367978692486745621757064307866143997529010856187698866761085397967488612326286182291301655780420802213700700872824442868225191222911023750488609973480926167606063152176688092948837104972...

output:

447917122
738150576
134709012
571675718
0

result:

ok 5 lines

Test #9:

score: 0
Accepted
time: 862ms
memory: 74492kb

input:

5
7612942550467855237767978070830743429305395120370014044416141696259440200835613011108477499855450341979327882148431400498007877975643997499046007388707405687392636406520850657394581417406913024784851871291661719356877660941151602720564069428677800545614776632869404791295787921432277016643912651129...

output:

0
264129072
541216127
357954287
0

result:

ok 5 lines

Test #10:

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

input:

5
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

0
0
0
0
0

result:

ok 5 lines

Test #11:

score: -100
Time Limit Exceeded

input:

5
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

910755804
259808709
937821856
357970005
357970004

result: