QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#354463#7996. 报数 IVPorNPtree#WA 25ms74496kbC++141.3kb2024-03-15 14:03:432024-03-15 14:03:45

Judging History

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

  • [2024-03-15 14:03:45]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:74496kb
  • [2024-03-15 14:03:43]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

int calc(int x, int y)
{
    if (!y) {
        return x;
    }
    if (y > 10) {
        return (x % 9 == 0 ? 9 : x % 9);
    }
    int A = 0;
    while (x) {
        A += x % 10;
        x = x / 10;
    }
    return calc(A, y - 1);
}

const int P = 1e9 + 7;

int f[1005][2][9005];

signed main()
{
    int T;
    scanf("%d", &T);
    while (T--) {
        string n;
        cin >> n;
        n = ' ' + n;
        memset(f, 0, sizeof(f));
        f[0][1][0] = 1;
        for (int i = 1; i < (int)n.size(); ++i) {
            for (int j = 0; j <= i * 9; ++j) {
                f[i][1][j] = f[i - 1][1][j - (n[i] - '0')];
                for (int k = 0; k <= 9 && k <= j; ++k) {
                    f[i][0][j] = (f[i][0][j] + f[i - 1][0][j - k]) % P;
                    if (k < n[i] - '0') {
                        f[i][0][j] = (f[i][0][j] + f[i - 1][1][j - k]) % P;
                    }
                }
            }
        }
        int k, m, A = 0;
        scanf("%d%d", &k, &m);
        for (int i = 1; i <= (int)(n.size() - 1) * 9; ++i) {
            if (calc(i, k - 1) == m) {
                A = (0ll + A + f[(int)n.size() - 1][0][i] + f[(int)n.size()][1][i]) % P;
            }
        }
        printf("%d\n", A);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 16ms
memory: 74496kb

input:

2
114 1 5
514 2 10

output:

8
10

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 25ms
memory: 74484kb

input:

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

output:

8
10
12723
504
481046284

result:

wrong answer 3rd lines differ - expected: '12724', found: '12723'