QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#111449#6522. Digit ModeToboWA 9ms4996kbC++201.2kb2023-06-07 09:42:022023-06-07 09:42:05

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-07 09:42:05]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:4996kb
  • [2023-06-07 09:42:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define N 100005
#define mod 1'000'000'007

int dig[51], cnt;
map<vector<int>, int> dp[51][2];
int dfs(vector<int> sta, int cur, int zero, int limit)
{
    if (!cur)
    {
        int mx = *max_element(sta.begin(), sta.end()), ans = 0;
        for (int i = 0; i <= 9; i++)
            if (mx && sta[i] == mx)
                ans = i;
        if (!limit)
            dp[cur][zero][sta] = ans;
        return ans;
    }
    if (!limit && dp[cur][zero].count(sta))
        return dp[cur][zero][sta];
    int res = 0;
    for (int i = 0; i <= (limit ? dig[cur] : 9); i++)
    {
        if (!zero || i)
            sta[i]++;
        res = (res + dfs(sta, cur - 1, zero && (i == 0), limit && (i == dig[cur]))) % mod;
        if (!zero || i)
            sta[i]--;
    }
    if (!limit)
        dp[cur][zero][sta] = res;
    return res;
}
void solve()
{
    string s;
    cin >> s;
    cnt = 0;
    for (char c : s)
        dig[++cnt] = c - '0';
    cout << dfs(vector<int>(10, 0), cnt, 1, 1) << '\n';
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    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: 9ms
memory: 4996kb

input:

5
9
99
999
99999
999999

output:

45
615
6570
597600
5689830

result:

ok 5 number(s): "45 615 6570 597600 5689830"

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3472kb

input:

34
7
48
8
76
1
97
7
5
7
7
2
89
9
4
84
46
6
73
86
78
5
3
8
9
31
24
78
7
11
45
2
65
88
6

output:

28
484
36
354
1
444
28
15
28
28
3
606
45
10
236
335
21
173
362
508
15
6
36
45
52
202
508
28
47
270
3
281
516
21

result:

wrong answer 2nd numbers differ - expected: '236', found: '484'