QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#148670#6300. Best Carry Player 2lzhmWA 1ms3752kbC++141.5kb2023-08-23 17:21:462023-08-23 20:25:29

Judging History

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

  • [2023-08-23 20:25:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3752kb
  • [2023-08-23 17:21:46]
  • 提交

answer

#include<bits/stdc++.h>
#define int __int128
using namespace std;
int T,x,k;
int dp[40][40][2],base[40];
//dp[i][j][0/1]:当前考虑到第i位,进位了j次,当前是否进位
template <typename T>
inline void read(T &x){
	bool f=0; x=0; char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') f=1; ch=getchar();}
	while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	x=f?-x:x;
}
void write(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
signed main(){
	base[0]=(int)1;
	for(int i=1;i<=37;i++) base[i]=base[i-1]*(int)10;
	read(T);
	while(T--){
		read(x); read(k);
		int a[37],len=(int)0,tmp=x;
		memset(a,0,sizeof(a));
		while(tmp){a[++len]=tmp%(int)10; tmp/=(int)10;}
		len+=k;
		if(!k){
			if(a[1]!=9){puts("0"); continue;}
			int flag=len+1;
			for(int i=1;i<=len;i++)
				if(a[i]!=(int)9){
					flag=i+1;
					break;
				}
			putchar('1');
			for(int i=1;i<flag;i++) putchar('0');
			printf("\n");
			continue;
		}
		memset(dp,0x3f,sizeof(dp));
		int inf=dp[0][0][0];
		for(int i=0;i<=37;i++) dp[i][0][0]=0;
		for(int i=1;i<=37;i++){
			for(int j=0;j<=k;j++){
				dp[i][j][0]=min(dp[i][j][0],dp[i-1][j][0]);
				if(a[i]!=9) dp[i][j][0]=min(dp[i][j][0],dp[i-1][j][1]);
				if(a[i] && j) dp[i][j][1]=min(dp[i][j][1],dp[i-1][j-1][0]+base[i-1]*(10-a[i]));
				if(j) dp[i][j][1]=min(dp[i][j][1],dp[i-1][j-1][1]+base[i-1]*(10-a[i]-1));
			}
		}
		int ans=min(dp[len][k][0],dp[len][k][1]);
		write(ans==inf?-1:ans); puts(" ");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3752kb

input:

4
12345678 0
12345678 5
12345678 18
990099 5

output:

0
54322 
999999999987654322 
9910 

result:

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