QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#657934 | #7996. 报数 IV | yuanyq5523# | WA | 199ms | 82096kb | C++20 | 2.2kb | 2024-10-19 15:48:07 | 2024-10-19 15:48:08 |
Judging History
answer
/*
ANALYSIS:
*/
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <ctime>
#include <random>
#define int long long
#define endl '\n'
using namespace std;
const int N=1e3+5;
const int mx=1e3;
const int mod=1e9+7;
int A[N][N*10],psum[N];
int n,k,m;
string S;
void cal(){
A[0][0]=1;
for (int j=1;j<=mx;j++) A[0][j]=0;
for (int i=1;i<=mx;i++){
for (int j=0;j<=mx*10;j++){
for (int k=max(j-9,0ll);k<=j;k++){
A[i][j]=(A[i][j]+A[i-1][k])%mod;
}
}
}
// cout<<"A"<<endl;
// for (int i=1;i<=20;i++){
// for (int j=0;j<=20;j++){
// cout<<A[i][j]<<' ';
// }cout<<endl;
// }
}
int C(int value)
{
vector<int> ans(n+5,0);
for (int i=1;i<=n;i++)//后i位
{
int x=(int)(S[n-i+1]-'0'),cnt=0;
for (int j=0;j<=x-1&&value-psum[n-i]-j>=0;j++) cnt=(cnt+A[i-1][value-psum[n-i]-j])%mod;
ans[i]=(cnt+ans[i-1])%mod;
}
return ans[n]%mod;
}
inline int f(int n)
{
int res=0;
while(n>0)
{
res+=n%10;
n/=10;
}
return res;
}
void solution()
{
cin>>S>>k>>m;
n=S.length();
S=' '+S;
psum[0]=0;
for(int i=1;i<=n;i++)
{
psum[i]+=S[i]-'0'+psum[i-1];
}
int finalans=0;
for(int i=1;i<=9000;i++)
{
int ti=i;
for(int t=1;t<=k-1;t++)
{
if(ti<=9)break;
ti=f(ti);
}
if(ti==m)
{
//cout<<i<<' '<<C(i)<<endl;
finalans=(finalans+C(i))%mod;
}
}
cout<<finalans<<endl;
// int cnt=0,psum=0;
// for(int i=1;i<=n;i++)psum+=S[i]-'0';
// vector<int> ans(n+5,0);
// for (int i=1;i<=n;i++)//后i位
// {
// int x=(int)(S[n-i+1]-'0'),cnt=0;
// psum+=x;
// for (int j=0;j<=x-1;j++) cnt=(cnt+A[i-1][psum-j])%mod;
// ans[i]=(cnt+ans[i-1])%mod;
// }
// cout<<ans[n]<<endl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cal();
int T = 1;
cin >> T;
for (int i=1;i<=T;i++) {
try {
//cerr<<"Case #"<<i<<": "<<endl;
solution();
} catch (const char* e) {
// cerr << "Caught exception in solution: " << e << endl;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 199ms
memory: 81984kb
input:
2 114 1 5 514 2 10
output:
8 10
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 189ms
memory: 82096kb
input:
5 114 1 5 514 2 10 114514 3 7 1919810 2 13 1145141919810114514191981011451419198101145141919810114514191981011451419198101145141919810114514191981011451419198101145141919810 1 79
output:
8 10 12724 8329 679770954
result:
wrong answer 4th lines differ - expected: '504', found: '8329'