QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#377476 | #7996. 报数 IV | plutos | TL | 18ms | 74160kb | C++17 | 1.6kb | 2024-04-05 14:04:42 | 2024-04-05 14:04:44 |
Judging History
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];
const int mod = 1e9 + 7;
//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));
tmp%=mod;
}
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();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 74160kb
input:
2 114 1 5 514 2 10
output:
8 10
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 18ms
memory: 74080kb
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 932367667