QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#244669 | #6300. Best Carry Player 2 | hhoppitree# | WA | 1ms | 3464kb | C++14 | 1.8kb | 2023-11-09 14:19:16 | 2023-11-09 14:19:16 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
char s[40],t[40];
int T,n;
__int128 F[40][2][40],p10[40];
__inline void ckmin(__int128&A,__int128 B){(A>B)?(A=B):0;}
__inline void print(__int128 x)
{
if(x>=10)print(x/10);
putchar(x%10+'0');
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
cin>>T;
p10[0]=1;
for(int i=1;i<=36;++i)p10[i]=p10[i-1]*10;
while(T--)
{
int k;
cin>>s+1>>k;
n=strlen(s+1);int j=n,i;
for(i=36;i&&j;--i)s[i]=s[j--];
while(i)s[i--]='0';
if(!k)
{
int u=36;
while(s[u]=='9')--u;
putchar('1');
for(int i=u+1;i<=36;++i)putchar('0');
putchar('\n');
continue;
}
// cerr<<s+1<<endl;
memset(F,0x3f,sizeof F);
F[1][0][0]=0;
for(int i=1;i<=36;++i)
{
for(int j=0;j<2;++j)
for(int u=0;u<i;++u)if(F[i][j][u]<=1e37)
{
int o=s[i]-'0';
__int128 w=F[i][j][u];
// cerr<<"F[ "<<i<<"]["<<j<<"]["<<u<<"]="<<w<<endl;
for(int k=0;k<10;++k)
{
if(o+k==9)
{
if(i!=36)ckmin(F[i+1][1][u+1],w+p10[36-i]*k);
else if(!j)ckmin(F[i+1][0][u],w+p10[36-i]*k);
}
else if(o+k>=10)
ckmin(F[i+1][0][u+1],w+p10[36-i]*k);
else if(!j)
ckmin(F[i+1][0][u],w+p10[36-i]*k);
}
}
}
print(F[37][0][k]);
putchar('\n');
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3460kb
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: 3464kb
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 84069761239290679208598432424319205183 84069761239290679208598432424319205183 84069761239290679208598432424319205183 84069761239290679208598432424319205183 84069761239290679208598432424319205183 84069761239290679208598432424319205183 84069761239290679208598432424319205183 84069761239290679208...
result:
wrong answer 2nd lines differ - expected: '10000', found: '84069761239290679208598432424319205183'