QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#302992#6300. Best Carry Player 2ZYF_B#WA 0ms3620kbC++142.0kb2024-01-11 16:37:192024-01-11 16:37:20

Judging History

你现在查看的是最新测评结果

  • [2024-01-11 16:37:20]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3620kb
  • [2024-01-11 16:37:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int ti;
char sa[25];
int st[25],sr[2500];
__int128 dp[25][25][2],pw[25];
__int128 min(__int128 x,__int128 y,__int128 z)
{
	return min(x,min(y,z));
}
void write(__int128 x)
{
	if(x==0)putchar('0');
	int st[40],cnt=0;
		while(x)
		{
			st[++cnt]=x%10;
			x/=10;
		}
		for(int i=cnt;i;i--)
		putchar(st[i]+'0');
}
__int128 dfs(int x,int n,int k)
{
	if(x==0)
	{
		if(n==0&&k==0)
		return 0;
		else return 1e36;
	}
	if(dp[x][n][k]!=-1)return dp[x][n][k];
	__int128 &res=dp[x][n][k]; res=1e36;
	if(st[x]==0)
	{
		if(k==0)res=min(res,dfs(x-1,n,0),dfs(x-1,n,1));
		else if(n)res=dfs(x-1,n-1,1)+(__int128)pw[x-1]*9;
	}
	else if(st[x]==9)
	{
		if(k==0)res=min(res,dfs(x-1,n,0));
		else if(n)res=min(res,dfs(x-1,n-1,1),dfs(x-1,n-1,0)+pw[x-1]);
	}
	else
	{
		if(k==0)res=min(res,dfs(x-1,n,0),dfs(x-1,n,1));
		else if(n)res=min(res,dfs(x-1,n-1,1)+(9-st[x])*pw[x-1],dfs(x-1,n-1,0)+(10-st[x])*pw[x-1]);
	}
	//cout<<x<<" "<<n<<" "<<k<<" "<<(long long)dp[x][n][k]<<"\n"; 
	return res;
}
void solve()
{
	int x,k;
	cin>>x>>k;
	int cnt=0;
	while(x)
	{
		st[++cnt]=x%10;
		x/=10;
	}
	if(k==0)
	{
		for(int i=1;i<=cnt;i++)
		{
			if(st[i]!=9)
			{
				cout<<"1";
				for(int j=1;j<=i-1;j++)
				cout<<"0";
			}
			cout<<"\n"; 
			return;
		}
		cout<<"1";
		for(int i=1;i<=cnt;i++)cout<<"0";
		cout<<"\n";
		return;
	}
	int fi=1;
	for(int i=1;i<=cnt;i++)if(st[i]==0)fi++,sr[i]=0;else break;
	if(k>=(cnt-fi)+1)
	{
		for(int i=fi;i<=cnt;i++)
		{
			if(i==fi)sr[i]=10-st[i];
			else sr[i]=9-st[i];
		}
		for(int i=(cnt-fi)+2;i<=k;i++)
		{
			cout<<"9";
		}
		for(int i=cnt;i>=1;i--)
		{
			cout<<sr[i];
		}
		cout<<"\n";
	}
	else
	{
		memset(dp,-1,sizeof(dp));
		write(min(dfs(cnt,k,0),dfs(cnt,k,1)));puts("");
	}
} 
signed main()
{
	cin>>ti;
	pw[0]=1;
	pw[1]=10;
	for(int i=2;i<=25;i++)
	{
		pw[i]=pw[i-1]*pw[1];
	}
	while(ti--)
	{
		solve();
	}
} 

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3620kb

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: 3608kb

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:


10000
1000
100
10
1
900001
9900001
99900001
999900001
10000000001
9999910000
9999901000
9999900100
9999900010
000009999900001
9000009999900001
99000009999900001
999000009999900001
99999999999999999900000000000000000


result:

wrong answer 1st lines differ - expected: '100000', found: ''