QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#128862 | #6300. Best Carry Player 2 | lefy | WA | 1ms | 3840kb | C++14 | 1.3kb | 2023-07-21 16:21:54 | 2023-07-21 16:34:25 |
Judging History
answer
#include<bits/stdc++.h>
#define ll __int128
using namespace std;
int p[40],num[20];
ll dp[20][20][2],pw[19];
void sc(ll x){
int len=0;
do num[len++]=x%10;while(x/=10);
while(len--)putchar(num[len]+'0');
}
void solve(){
long long xx;int k;scanf("%lld%d",&xx,&k);
ll x=xx;
if(k==0){
ll ans=1;
while(x){
if(x%10!=9)break;
x/=10;ans*=10;
}
sc(ans);printf("\n");return;
}
int zero=0;
while(x%10==0)zero++,x/=10;
int m=0;
while(x){
p[++m]=x%10;x/=10;
}
for(int i=m+1;i<=k+1;i++)p[i]=0;
for(int i=0;i<=19;i++)for(int j=0;j<=19;j++)dp[i][j][0]=dp[i][j][1]=1e18;
dp[0][0][0]=0;m=max(m,k);
// cout<<m<<"\n";
for(int i=1;i<=m;i++){
dp[i][0][0]=min(dp[i-1][0][0],dp[i-1][0][1]);
for(int j=1;j<=min(k,i);j++){
dp[i][j][0]=dp[i-1][j][0];
if(p[i]!=9)dp[i][j][0]=min(dp[i-1][j][1],dp[i][j][0]);
dp[i][j][1]=min(dp[i-1][j-1][0]+pw[i-1]*(10-p[i]),dp[i-1][j-1][1]+pw[i-1]*(9-p[i]));
// sc(pw[i-1]*(10-p[i]));cout<<" ";
// sc(dp[i][j][0]);cout<<" ";
// cout<<<<" "<<dp[i][j][1]<<"\n";
}
// cout<<"\n";
}
sc(min(dp[m][k][0],dp[m][k][1]));
while(zero--)printf("0");printf("\n");
}
int main(){
pw[0]=1;
for(int i=1;i<=18;i++)pw[i]=pw[i-1]*10;
int T;scanf("%d",&T);
while(T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3620kb
input:
4 12345678 0 12345678 5 12345678 18 990099 5
output:
1 54322 999999999987654322 9910
result:
ok 4 lines
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3840kb
input:
21 999990000099999 0 999990000099999 1 999990000099999 2 999990000099999 3 999990000099999 4 999990000099999 5 999990000099999 6 999990000099999 7 999990000099999 8 999990000099999 9 999990000099999 10 999990000099999 11 999990000099999 12 999990000099999 13 999990000099999 14 999990000099999 15 999...
output:
100000 10000 1000 100 10 1 900001 9900001 99900001 999900001 10000000000 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 99999999999999999900000000000000000 1000000000000000000
result:
wrong answer 11th lines differ - expected: '10000000001', found: '10000000000'