QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#128908#6300. Best Carry Player 2yz_lyWA 1ms3688kbC++141.3kb2023-07-21 16:53:492023-07-21 16:56:32

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-21 16:56:32]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3688kb
  • [2023-07-21 16:53:49]
  • 提交

answer

#include<bits/stdc++.h>
#define ll __int128
using namespace std;
inline ll read(){
	char ch=getchar();
	ll f=1,x=0;
	while(ch<'0'||ch>'9'){
		if(ch=='-')
			f=-f;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
inline void work(ll k){
	if(k<0){
		putchar('-');
		k=-k;
	}
	if(k>9)
		work(k/10);
	putchar(k%10+'0');
}
ll t,x,dp[21][21][2];
int k;
int main(){
	t=read();
    while(t--){
        x=read();
        k=read();
        if(!k){
            for(int i=1;i<=20;i++){
                ll now=x/(ll)pow(10,i-1)%10;
                if(now!=9){
                    work((ll)pow(10,i-1));
                    break;
                }
            }
            putchar('\n');
            continue;
        }
        memset(dp,64,sizeof(dp));
        dp[0][0][0]=0;
        for(int i=1;i<=20;i++){
            ll now=x/(ll)pow(10,i-1)%10;
            for(int j=0;j<=k;j++){
                dp[i][j][0]=(now==9?dp[i-1][j][0]:min(dp[i-1][j][0],dp[i-1][j][1]));
                if(j)
                    dp[i][j][1]=(now==0?dp[i-1][j-1][1]+9*(ll)pow(10,i-1):min(dp[i-1][j-1][1]+(9-now)*(ll)pow(10,i-1),dp[i-1][j-1][0]+(10-now)*(ll)pow(10,i-1)));
            }
        }
        work(min(dp[20][k][0],dp[20][k][1]));
        putchar('\n');
    }
	return 0;
}

详细

Test #1:

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

input:

4
12345678 0
12345678 5
12345678 18
990099 5

output:

1
54322
999999999987655537
9910

result:

wrong answer 3rd lines differ - expected: '999999999987654322', found: '999999999987655537'