QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#134988 | #6300. Best Carry Player 2 | yzhang | WA | 1ms | 3660kb | C++14 | 2.5kb | 2023-08-05 10:30:22 | 2023-08-05 10:30:24 |
Judging History
answer
//μ's forever
#include <bits/stdc++.h>
#define ll long long
//#define getchar nc
using namespace std;
inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline ll read()
{
register ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return x*f;
}
inline void write(register int x)
{
if(!x)putchar('0');if(x<0)x=-x,putchar('-');
static int sta[20];register int tot=0;
while(x)sta[tot++]=x%10,x/=10;
while(tot)putchar(sta[--tot]+48);
}
int T,k;
ll n;
int a[40],tot,f[40][40][2];
int mst[40];
int main()
{
T=read();
while(T--){
n=read(),k=read();
tot=0;
memset(a,0,sizeof(a));
while(n){
++tot;
a[tot]=n%10;
n/=10;
}
memset(f,0,sizeof(f));
f[0][0][0]=1;
for(int i=1;i<=tot+k;++i)
for(int j=0;j<=k;++j){
//case 0
f[i][j][0]|=f[i-1][j][0];
if(a[i]!=9) f[i][j][0]|=f[i-1][j][1];
//case 1
if(a[i]!=0) f[i][j][1]|=f[i-1][j-1][0];
f[i][j][1]|=f[i-1][j-1][1];
}
bool fl=0;
if(f[tot+k][k][0]==0&&f[tot+k][k][1]==0) puts("-1");
else{
memset(mst,0,sizeof(mst));
int cur=k;
for(int i=tot+k;i>=1;--i){
int val=-1;
if(a[i]==9){
if(mst[i]==0&&f[i-1][cur][0]) val=0;
else if(cur&&f[i-1][cur-1][1]) val=0,--cur,mst[i-1]=1;
else val=1,--cur;
}else if(a[i]==0){
if(mst[i]==0&&f[i-1][cur][0]|f[i-1][cur][1]){
val=0;
}
else val=9,--cur,mst[i-1]=1;
}else{
if(mst[i]==0&&(f[i-1][cur][0]|f[i-1][cur][1])){
val=0;
if(f[i-1][cur][0]==0) mst[i-1]=1;
}
else if(cur&&f[i-1][cur-1][1]) val=10-a[i]-1,--cur,mst[i-1]=1;
else val=10-a[i],--cur;
}
if(val!=0) fl=1;
if(fl||i==1) printf("%d",val);
// cerr<<val;
}
puts("");
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3660kb
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'