QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#377475#7996. 报数 IVplutosWA 25ms74168kbC++171.5kb2024-04-05 14:03:442024-04-05 14:03:44

Judging History

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

  • [2024-04-05 14:03:44]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:74168kb
  • [2024-04-05 14:03:44]
  • 提交

answer

#include <bits/stdc++.h>

void Yes() {
    std::cout << "YES" << "\n";
    return;
}

void No() {
    std::cout << "NO" << "\n";
    return;
}

template<typename T>
void out(T x) { std::cout << x << "\n"; }

using namespace std;
using ll = long long;
using PII = pair<ll, ll>;

const ll N = 2e5 + 10;

ll k, m;
string n;
ll a[1005];
ll dp[1004][9004];

//ll tong[9001];
ll cc(ll x) {
    ll tmp = 0;
    while (x) {
        tmp += x % 10;
        x /= 10;
    }
    return tmp;
}

ll dfs(ll pos, ll sum, ll lim, ll lead0) {
    if (pos == 0) {

        for (ll i = 1; i <= k - 1; i++) {
            sum = cc(sum);
        }
        return sum == m;
    }

    if (!lim && !lead0 && dp[pos][sum] != -1) {
        return dp[pos][sum];
    }
    ll up = lim ? a[pos] : 9;
    ll tmp = 0;
    for (ll i = 0; i <= up; i++) {
        tmp += dfs(pos - 1, sum + i, lim && (i == up), lead0 && (i == 0));
    }
    if (!lim && !lead0) {
        return dp[pos][sum] = tmp;
    }
    return tmp;
}

ll cal(string s) {
    ll len = 0;
    reverse(s.begin(), s.end());
    for (auto p: s) {
        a[++len] = p - '0';
    }
    return dfs(len, 0, 1, 1);
}

void Solve() {
    for (ll i = 0; i <= 1002; i++)
        for (ll j = 0; j <= 9001; j++)
            dp[i][j] = -1;
    cin >> n >> k >> m;
    k = min(k, 5ll);
    cout << cal(n) <<"\n";
//    for(ll i = 1;i<=20;i++) {
//        cout<<tong[i]<<"\n";
//    }
}

signed main() {

    ll t = 1;
    cin>>t;
    while (t--)
        Solve();
}

详细

Test #1:

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

input:

2
114 1 5
514 2 10

output:

8
10

result:

ok 2 lines

Test #2:

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

input:

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

output:

8
10
12724
504
-2412010376935373306

result:

wrong answer 5th lines differ - expected: '481046284', found: '-2412010376935373306'