QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#619477 | #6300. Best Carry Player 2 | realman | WA | 0ms | 3844kb | C++14 | 1.1kb | 2024-10-07 14:18:54 | 2024-10-07 14:18:56 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=20;
int T,K,a[N],ans[N];char s[N];
__int128 p[N],f[N][N][2];
int main()
{
scanf("%d",&T);
p[0]=1;
for(int i=1;i<=17;i++)
p[i]=p[i-1]*10;
while(T--)
{
memset(a,0,sizeof(a));
scanf("%s %d",s,&K);
int n=strlen(s);
for(int i=0;i<n;i++)
a[i]=s[i]-'0';
for(int i=0;i<n/2;i++)
swap(a[i],a[n-1-i]);
if(K==0)
{
int cnt=0;
for(int i=0;i<=18;i++)
if(a[i]==9)
ans[++cnt]=0;
else
{
ans[++cnt]=1;
break;
}
for(int i=cnt;i>=1;i--) printf("%d",ans[i]);
cout<<endl;
continue;
}
memset(f,0x7f,sizeof(f));
f[0][0][0]=0;
for(int i=0;i<=17;i++)
for(int j=0;j<=K;j++)
for(int k=0;k<2;k++)
{
if(a[i]+k<=9) f[i+1][j][0]=min(f[i+1][j][0],f[i][j][k]);
if(a[i]+k>0&&j<K) f[i+1][j+1][1]=min(f[i+1][j+1][1],f[i][j][k]+(10-a[i]-k)*p[i]);
}
__int128 tmp=min(f[18][K][0],f[18][K][1]);
int cnt=0;
while(tmp>0) ans[++cnt]=tmp%10,tmp/=10;
for(int i=cnt;i>=1;i--) printf("%d",ans[i]);
cout<<endl;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3844kb
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: 3820kb
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 169473963133173273960190490760135540607 1000000000000000000
result:
wrong answer 20th lines differ - expected: '99999999999999999900000000000000000', found: '169473963133173273960190490760135540607'