QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#128923 | #6300. Best Carry Player 2 | OFforest_1273 | WA | 1ms | 3708kb | C++14 | 1.4kb | 2023-07-21 16:59:07 | 2023-07-21 17:00:21 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int read(){int s=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9')s=(s<<1)+(s<<3)+(c^48),c=getchar();return s*f;}
const int N=20;
int T,k,n,m,zero,val[N];
char x[N];
LL f[N][N][2]/*f[i][j][0/1]:当前考虑到第i位 进位了j次 当前位有没有进位(会给下一位加1)情况下最小的y*/,base[N];
int main(){
T=read(),base[0]=1;
for(int i=1;i<N;++i)base[i]=base[i-1]*10;
while(T--){
scanf("%s",x+1),k=read(),n=m=strlen(x+1),zero=0;
if(!k){printf("1\n");continue;}/*特判*/
while(m>=1&&x[m]=='0')--m,++zero;/*末尾0不影响进位*/
for(int i=1;i<=m;++i)val[i]=x[m-i+1]-'0';/*反过来*/
memset(f,0x3f,sizeof(f));
f[0][0][0]=0;
for(int i=1;i<N-1/*可能进k位后会很大 18位*/;++i){
for(int j=0;j<=k;++j){
f[i][j][0]=min(f[i][j][0],f[i-1][j][0]);
if(val[i]!=9)f[i][j][0]=min(f[i][j][0],f[i-1][j][1]);/*如果val[i]=9的话就会连续进位两次 不满足*/
if(val[i]/*0肯定进不了位*/&&j)f[i][j][1]=min(f[i][j][1],f[i-1][j-1][0]+1ll*(10-val[i])*base[i-1]);
if(j)f[i][j][1]=min(f[i][j][1],f[i-1][j-1][1/*已经给val[i]加了1*/]+1ll*(9-val[i]/*可以少加1*/)*base[i-1]);
}
}
LL ans=min(f[N-2][k][0],f[N-2][k][1]);
printf("%lld",ans);
while(zero){printf("0");--zero;}
printf("\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3708kb
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: 3664kb
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:
1 10000 1000 100 10 1 900001 9900001 99900001 999900001 10000000001 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 99900000999990000900000000000000000 1
result:
wrong answer 1st lines differ - expected: '100000', found: '1'