QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#508664#7606. Digital Nimno_RED_no_DEADWA 0ms53372kbC++201.0kb2024-08-07 18:51:382024-08-07 18:51:39

Judging History

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

  • [2024-08-07 18:51:39]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:53372kb
  • [2024-08-07 18:51:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int f[25][505][1005];
int a[105];

// 0 9 7 8 3

/*
    [pos][sum][nw ?][lim] = last(now)
    k = last((l - 1) * 10^e);
    
    f(x, k, lim) = f(x + 0, k, lim) -> f(x + 1, f0, lim) -> f(...) -> f(x + 9, f8, lim)
    
*/

int dfs(int dep,int x,int k,int lim)
{
	if(dep==-1)
	{
		if(x<k) return 1;
		return k+1;
	}
	
    if (!lim && f[dep][x][k] != -1) return f[dep][x][k];
	int mx = 9, nw = k;
	if (lim) mx = a[dep];

	for (int i = 0; i <= mx; i ++)
		nw = dfs(dep - 1, x + i, nw,lim==1&&i==mx);

    //cout << "Debug: " << dep << ' ' << x << ' ' << k << ' ' << nw << endl;
	//printf("dfs:dep=%d,x=%d,k=%d,lim=%d,nw=%d\n",dep,x,k,lim,nw);
	if(!lim) f[dep][x][k]=nw;
	return nw;
}

int main()
{
	memset(f,-1,sizeof(f));
	int T;
	scanf("%d",&T);
	while(T--)
	{
		long long n;
		scanf("%lld",&n);
		int t=0;
		while(n)
		{
			a[t++]=n%10;
			n/=10;
		//	printf("n=%lld\n",n);
		}
        printf("%d\n", dfs(t - 1,0,1,1));
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 53372kb

input:

4
1
10
42
190

output:

2
1
3
11

result:

wrong answer 1st lines differ - expected: 'Algosia', found: '2'