QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#658329 | #7996. 报数 IV | yuanyq5523# | WA | 210ms | 82580kb | C++20 | 2.5kb | 2024-10-19 16:38:33 | 2024-10-19 16:38:38 |
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*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;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;
}
}
int cnt=0;
for(int i=1;i<=S.length()-1;i++)cnt+=S[i]-'0';
int ti=cnt;
for(int t=1;t<=k-1;t++)
{
if(ti<=9)break;
ti=f(ti);
}
if(ti==m)finalans++;
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: 0
Wrong Answer
time: 210ms
memory: 82580kb
input:
2 114 1 5 514 2 10
output:
1
result:
wrong answer 1st lines differ - expected: '8', found: '1'