QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#627100#7996. 报数 IVhhhyh#WA 27ms82048kbC++231.4kb2024-10-10 14:44:212024-10-10 14:44:21

Judging History

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

  • [2024-10-10 14:44:21]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:82048kb
  • [2024-10-10 14:44:21]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define all(x) x.begin(), x.end()
const int N = 9999 + 10;
#define int long long
int bad[N];
int mod = 1e9 + 7;
// k>=1
void change(int &x)
{
    int y = 0;
    while (x)
    {
        y += x % 10;
        x /= 10;
    }
    swap(x, y);
}
void make_bad(i64 n, i64 k)
{
    for (int i = 0; i <= 9999; i++)
    {
        bad[i] = 0;
        int x = i;
        for (int j = 0; x >= 10 && j < k - 1; j++)
            change(x);
        if (x == n)
            bad[i] = 1;
    }
}
/*
1
114 1 5
*/
int dp[1000][N];
int dfs(string &s, int n, int sum, int flag)
{
    if (n == 0)
    {
        return bad[sum];
    }
    if (~dp[n][sum])
        return dp[n][sum];
    dp[n][sum] = 0;
    int hi = flag ? s[n - 1] - '0' : 9;
    for (int lo = 0; lo <= hi; lo++)
    {
        dp[n][sum] += dfs(s, n - 1, sum + lo, (flag) && (lo == hi));
        dp[n][sum] %= mod;
    }
    return dp[n][sum];
}
void solve()
{
    memset(dp, -1, sizeof dp);
    string s;
    cin >> s;
    int n, k;
    cin >> k >> n;
    make_bad(n, k);
    //(g,n,k)<=1e6
    reverse(all(s));
    // 状态数位和[1000][9999],1e8种状态
    i64 res = dfs(s, s.size(), 0, true);

 
    cout << res << endl;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 81816kb

input:

2
114 1 5
514 2 10

output:

8
10

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 27ms
memory: 82048kb

input:

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

output:

8
10
13333
504
238052145

result:

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