QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#292105 | #6300. Best Carry Player 2 | fstqwq# | WA | 0ms | 3920kb | C++14 | 1.6kb | 2023-12-27 18:30:31 | 2023-12-27 18:30:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int L=22;
LL dp[L][L][2];
LL n,m,fc[L];
void init(){
fc[0]=1;for(int i=1;i<=18;i++)fc[i]=fc[i-1]*10;
}
LL getbit(LL x,int y){return (x/fc[y-1])%10;}
LL getval(LL x,int y){return x*fc[y-1];}
LL add(LL x,LL y){
if(x==-1)return -1;
else return x+y;
}
LL upd(LL x,LL y){
if(x==-1)return y;
else if(y==-1)return x;
else return min(x,y);
}
void solve(){
scanf("%lld%lld",&n,&m);
if(!m){
for(int i=1;i<=19;i++){
if(getbit(n,i)<9){
printf("%lld\n",fc[i-1]);
return ;
}
}
}
int cnt=0;
while(n%10==0)n/=10,cnt++;
memset(dp,-1,sizeof(dp));
dp[0][0][0]=0;
for(int i=1;i<=18;i++){
LL x=getbit(n,i);
if(!x){
for(int j=0;j<i;j++)dp[i][j][0]=upd(dp[i-1][j][0],dp[i-1][j][1]);
for(int j=1;j<=i;j++)dp[i][j][1]=add(dp[i-1][j-1][1],getval(9,i));
}
else if(x==9){
for(int j=0;j<i;j++)dp[i][j][0]=dp[i-1][j][0];
for(int j=1;j<=i;j++)dp[i][j][1]=upd( dp[i-1][j-1][1] , add(dp[i-1][j-1][0],getval(1,i)) );
}
else{
for(int j=0;j<i;j++)dp[i][j][0]=upd(dp[i-1][j][0],dp[i-1][j][1]);
for(int j=1;j<=i;j++)dp[i][j][1]=upd( add(dp[i-1][j-1][1],getval(9-x,i)) , add(dp[i-1][j-1][0],getval(10-x,i)) );
}
}
printf("%lld",upd(dp[18][m][0],dp[18][m][1]));
while(cnt){putchar(' ');cnt--;}
putchar('\n');
}
int main(){
init();
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: 0ms
memory: 3920kb
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: 0ms
memory: 3856kb
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 999999999999999999 1000000000000000000
result:
wrong answer 20th lines differ - expected: '99999999999999999900000000000000000', found: '999999999999999999 '