QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#129400 | #6300. Best Carry Player 2 | yz_ly | WA | 1ms | 3564kb | C++14 | 1.6kb | 2023-07-22 18:53:07 | 2023-07-22 18:53:11 |
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[41][41][2];
int k;
ll power(ll a,ll b){
ll sum=1,k=a;
while(b){
if(b&1ll)
sum*=k;
k*=k;
b>>=1ll;
}
return sum;
}
int main(){
t=read();
while(t--){
x=read();
k=read();
if(!k){
for(int i=1;i<=20;i++){
ll now=x/(ll)power(10,i-1)%(ll)10;
if(now!=9){
work((ll)power(10,i-1));
break;
}
}
putchar('\n');
continue;
}
memset(dp,64,sizeof(dp));
dp[0][0][0]=0;
for(int i=1;i<=37;i++){
ll now=x/(ll)power(10,i-1)%(ll)10;
for(int j=0;j<=k;j++){
dp[i][j][0]=(now==(ll)9?dp[i-1][j][0]:min(dp[i-1][j][0],dp[i-1][j][1]));
if(j)
dp[i][j][1]=(now==(ll)0?dp[i-1][j-1][1]+(ll)9*(ll)power(10,i-1):min(dp[i-1][j-1][1]+(9-now)*(ll)power(10,i-1),dp[i-1][j-1][0]+(10-now)*(ll)power(10,i-1)));
}
}
ll ans=min(dp[20][k][0],dp[20][k][1]);
if(ans>(ll)1e37)
work(k);
else
work(ans);
putchar('\n');
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
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: 3528kb
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 10000000001 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 18 1000000000000000000
result:
wrong answer 20th lines differ - expected: '99999999999999999900000000000000000', found: '18'