QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#627177#7996. 报数 IVhhhyh#TL 9ms15044kbC++231.4kb2024-10-10 15:05:482024-10-10 15:05:51

Judging History

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

  • [2024-10-10 15:05:51]
  • 评测
  • 测评结果:TL
  • 用时:9ms
  • 内存:15044kb
  • [2024-10-10 15:05:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define all(x) x.begin(), x.end()
const int N = 9000 + 10;
int ch[N][4];
int mod = 1e9 + 7;
void change(int &x)
{
    int y = 0;
    while (x)
    {
        y += x % 10;
        x /= 10;
    }
    swap(x, y);
}
void init()
{
    for (int i = 1; i <= 9000; i++)
    {
        int x = i;
        for (int j = 0; j < 4; j++)
        {
            ch[i][j] = x;
            change(x);
        }
    }
}
int dp[1000][N][2];
int vis[1000][N][2];
int cnt = 0;
int m, k;
string s;
int dfs(int n, int sum, int flag)
{
    assert(sum <= 9000);
    if ((s.size() - n) * 9 + sum < m)
        return 0;
    if (n == s.size())
        return ch[sum][k - 1] == m;
    if (vis[n][sum][flag] == cnt)
        return dp[n][sum][flag];
    vis[n][sum][flag] = cnt;
    int &res = dp[n][sum][flag];
    res = 0;
    int hi = flag ? s[n] - '0' : 9;
    for (int lo = 0; lo <= hi; lo++)
    {
        res += dfs(n + 1, sum + lo, (flag) && (lo == hi));
        res %= mod;
    }
    return res;
}
void solve()
{
    cin >> s;
    cin >> k >> m;
    k = min(k, 4);
    ++cnt;
    i64 res = dfs(0, 0, true);
    cout << res << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    init();
    while (T--)
        solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5840kb

input:

2
114 1 5
514 2 10

output:

8
10

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 9ms
memory: 15044kb

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:

0
613343513
0
500149787

result: