QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#735460 | #6300. Best Carry Player 2 | dsbdsb# | WA | 0ms | 3664kb | C++14 | 745b | 2024-11-11 20:11:13 | 2024-11-11 20:11:13 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=(k);++i)
#define MAXN 25
typedef long long ll;
ll task,n,m,cnt,a[MAXN];
ll base[MAXN],f[MAXN][MAXN][2];
inline void solve(){
std::cin>>n>>m;
base[0]=1;
rep(i,1,18) base[i]=base[i-1]*10;
while(n%10==0) ++cnt,n/=10;
rep(i,1,18) a[i]=n%10,n/=10;
rep(i,0,18) rep(j,0,18) rep(k,0,1) f[i][j][k]=1e18;
f[0][0][0]=0;
rep(i,0,17) rep(j,0,i) rep(k,0,1){
ll cur=a[i+1]+k;
ll &x=f[i+1][j+(cur>=10)][cur>=10];
ll &y=f[i+1][j+1][1];
x=std::min(x,f[i][j][k]);
y=std::min(y,f[i][j][k]+base[i]*(10-cur));
}
std::cout<<std::min(f[18][m][0],f[18][m][1]);
rep(i,1,cnt) std::cout<<0;
std::cout<<'\n';
}
int main(){
std::cin>>task;
while(task--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3664kb
input:
4 12345678 0 12345678 5 12345678 18 990099 5
output:
0 54322 999999999987654322 9910
result:
wrong answer 1st lines differ - expected: '1', found: '0'