QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#129900 | #6300. Best Carry Player 2 | Lq67122030 | WA | 1ms | 3676kb | C++14 | 1.3kb | 2023-07-23 07:52:33 | 2023-07-23 07:52:34 |
Judging History
answer
#include <bits/stdc++.h>
#define il inline
#define ll long long
using namespace std;
template<typename T> il T Min(const T x,const T y) { return x<y?x:y; }
const int N=25;
const ll inf=1e18;
ll x,f[N][N][2];
int k,m,n;
il void k0(){
putchar('1');
while(x%10==9) x/=10,putchar('0');
puts("");
}
il void work(){
scanf("%lld%d",&x,&k);
if(!k) return k0();
ll p;
for(m=0;x%10==0;++m,x/=10);
for(int i=0;i<N;++i)
for(int j=0;j<=k;++j)
f[i][j][0]=0,f[i][j][1]=inf;
for(n=p=1;x;x/=10,++n,p=(p<<3)+(p<<1)){
const int now(x%10);
f[n][0][0]=0;
f[n][0][1]=f[n][n+1][0]=f[n][n+1][1]=inf;
for(int j=1;j<=k&&j<=n;++j){
if(now!=9) f[n][j][0]=Min(f[n-1][j][0],f[n-1][j][1]);
else f[n][j][0]=f[n-1][j][0];
if(now) f[n][j][1]=Min(f[n-1][j-1][0]+p*(10-now),f[n-1][j-1][1]+p*(9-now));
else f[n][j][1]=f[n-1][j-1][1]+p*(9-now);
}
}
--n;
if(n<=k){
p/=10;
for(int i=n;i<k;++i) putchar('9');
if(k>n) while(p>f[n][n][1]) putchar('0'),p/=10;
printf("%lld",f[n][n][1]);
for(int i=1;i<=m;++i) putchar('0');
puts("");
return;
}
ll ans(Min(f[n][k][0],f[n][k][1]));
if(ans==inf) return puts("-1"),void();
printf("%lld",ans);
for(int i=1;i<=m;++i) putchar('0');
puts("");
}
int main(){
int T;
scanf("%d",&T);
while(T--) work();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3676kb
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:
100000 0 1000 100 10 1 900001 9900001 99900001 999900001 10000000001 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 99999999999999999900000000000000000 1000000000000000000
result:
wrong answer 2nd lines differ - expected: '10000', found: '0'