QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#658249#7996. 报数 IVyuanyq5523#WA 208ms82112kbC++202.4kb2024-10-19 16:28:252024-10-19 16:28:25

Judging History

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

  • [2024-10-19 16:28:25]
  • 评测
  • 测评结果:WA
  • 用时:208ms
  • 内存:82112kb
  • [2024-10-19 16:28:25]
  • 提交

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*10;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) //f-1(value)的集合中小于N的个数
{
	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&&n-i>=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;
}

int cmp(string s,int m)
{
	if(s.length()>10)return 1;
	int n=0;
	for(int i=1;i<=s.length()-1;i++)
	{
		n=n*10+s[i]-'0';
	}
	if(n>m)return 1;
	else return 0;
}

void solution()
{
	cin>>S>>k>>m;
	n=S.length();
	S=' '+S;
	//cout<<"Q"<<S<<' '<<k<<' '<<m<<endl;
	psum[0]=0;
	for(int i=1;i<=n;i++)
	{
		psum[i]=S[i]-'0'+psum[i-1];
	}
	// if(k==1)
	// {
	// 	int finalans=C(m)%mod;
	// 	cout<<finalans<<endl;
	// 	return;
	// }
	int finalans=0;
	for(int i=1;i<=9000;i++)
	{
		//if(cmp(S,i)==0)continue;
		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;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	//freopen("/Users/Kai/NewCode/contest/VPXCPC/input.txt","r",stdin);
	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: 205ms
memory: 82112kb

input:

2
114 1 5
514 2 10

output:

8
10

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 208ms
memory: 82080kb

input:

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

output:

8
10
12723
504
481046284

result:

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