QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#627161#7996. 报数 IVhhhyh#TL 6ms17340kbC++231.5kb2024-10-10 15:00:382024-10-10 15:00:40

Judging History

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

  • [2024-10-10 15:00:40]
  • 评测
  • 测评结果:TL
  • 用时:6ms
  • 内存:17340kb
  • [2024-10-10 15:00:38]
  • 提交

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 bad[N];
int ch[N][4];
int mod = 1e9 + 7;
// k>=1
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);
        }
    }
}
/*
1
114 1 5
*/
int dp[1000][N][2];
int vis[1000][N][2];
int cnt = 0;
int m, k;
int dfs(string &s, int n, int sum, int flag)
{
    assert(sum <= 9000);
    if (n == -1)
        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(s, n - 1, sum + lo, (flag) && (lo == hi));
        res %= mod;
    }
    return res;
}
void solve()
{
    string s;
    cin >> s;
    cin >> k >> m;
    k=min(k,4);
    //(g,n,k)<=1e6
    ++cnt;
    reverse(all(s));
    // 状态数位和[1000][9999],1e8种状态
    i64 res = dfs(s, s.size() - 1, 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: 5692kb

input:

2
114 1 5
514 2 10

output:

8
10

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 6ms
memory: 17340kb

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

result: