QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#352843#7996. 报数 IVlopzithTL 77ms39104kbC++201.8kb2024-03-13 17:21:242024-03-13 17:21:24

Judging History

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

  • [2024-03-13 17:21:24]
  • 评测
  • 测评结果:TL
  • 用时:77ms
  • 内存:39104kb
  • [2024-03-13 17:21:24]
  • 提交

answer

#pragma GCC optimize("Ofast", "inline", "-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#define Arr std::vector
#define Ptn std::pair
#define fi first
#define se second
#define eb emplace_back
#define pb push_back
const int N = 1e3 + 5;
const int M = 9e3 + 5;
const int P = 1e9 + 7;
int T, n, k, m, f[N][M], t[2][M], op[M];
std::string s;

inline void Add(int &x, int y) { x += y; if (x >= P) x -= P; }

int dfs(int p, bool lim, int sum)
{
    if (p == n + 1) return (sum == 0);
    if (!lim && f[p][sum] != -1) return f[p][sum];
    int up = std::min(sum, (lim ? s[p] - '0' : 9)), res = 0;
    for (register int i = 0; i <= up; i++) Add(res, dfs(p + 1, lim && (i == (s[p] - '0')), sum - i));
    if (!lim) f[p][sum] = res;
    return res; 
}

signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> T;
    for (int i = 0; i < M; i++)
    {
        int x = i, cnt = 0; 
        while (x)
        {
            cnt += (x % 10);
            x /= 10;
        }
        op[i] = cnt;
    }
    while (T--)
    {
        // memset(t, 0, sizeof(t));
        memset(f, -1, sizeof(f));
        std::cin >> s; n = s.size(); s = " " + s;
        std::cin >> k >> m; 
        if (m > 9000) { printf("0\n"); continue; }
        int kel = 0;
        for (int i = 0; i <= 9000; i++) t[kel][i] = dfs(1, true, i); k--;
        // for (int i = 0; i <= 20; i++) printf("%lld ", t[kel][i]); printf("\n");
        k = std::min(4, k);
        for (int i = 1; i <= k; i++)
        {
            kel ^= 1; memset(t[kel], 0, sizeof(t[kel]));
            for (int j = 0; j <= 9000; j++) Add(t[kel][op[j]], t[kel ^ 1][j]);
        }
        std::cout << t[kel][m] << '\n';
    }
   
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 39104kb

input:

2
114 1 5
514 2 10

output:

8
10

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 77ms
memory: 39080kb

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: -100
Time Limit Exceeded

input:

5
3134666912140933323880320519044791121794814671711104987304374190280064994554822259889216567113228716903875026053927191961850586115167336109747673868148288830282192461669674173201533887392623483710043038941036243583011049049915834937139438028987629569618561762595613799223807979488245056374812076511...

output:


result: