QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#128908 | #6300. Best Carry Player 2 | yz_ly | WA | 1ms | 3688kb | C++14 | 1.3kb | 2023-07-21 16:53:49 | 2023-07-21 16:56:32 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
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'