QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#220839#6300. Best Carry Player 2kokosuki#WA 1ms3608kbC++141.6kb2023-10-20 21:30:592023-10-20 21:31:00

Judging History

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

  • [2023-10-20 21:31:00]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3608kb
  • [2023-10-20 21:30:59]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N =1e5+10;
int a[20],p[20];
int ans[40];
char x[40];
int k;
void ch(int l,int r)
{
	for(int i=l;i<=r;i++)
	{
		ans[i]=9-a[i];
		k--;
	}
	ans[r]++;
	if(l>1&&ans[l-1]>0) ans[l-1]--;
}
void sl()
{
	
	cin>> x+1;
	cin>>k;
	int n=strlen(x+1);
	for(int i=1;i<=n;i++)
	{
		a[i]=x[i]-'0';
//		cout<<a[i]<<' ';
	}
	if(k==0)
	{
		int flag=1;
		
		for(int i=n;i>=1;i--)
		{
			if(a[i]!=9)
			{
				cout<<p[n-i]<<endl;
				flag=0;
				break;
			}
		}
		if(flag) cout<<-1<<endl;
		return ;
	}
	int r;
	for(r=n;r;r--)
	{
		if(a[r]!=0) break;
	}
	int rr=r;
//	cout<<r<<endl;
	int l=r-k+1;
	int op=1;
//	cout<<l<<endl;
	if(l<1)
	{
		ch(1,r);
		while(k--)
		{
			cout<<9;
			l++;
		}
		
		for(int i=1;i<=r;i++)
		{
//			if(op==1&&ans[i]==0) continue;
//			if(ans[i]!=0) op=0;
			cout<<ans[i];
		}
	}
	else if(a[l-1]!=9||l==1)
	{
		ch(l,r);
		for(int i=l;i<=r;i++)
		{
			if(op==1&&ans[i]==0) continue;
			if(ans[i]!=0) op=0;
			cout<<ans[i];
		}
	}
	else
	{
		while(l>1&&a[l-1]==9) l--;
		r=l+k-1;
		rr=r;
		int cnt=0;
		while(r>l&&a[r]==0) r--,cnt++;
		while(cnt--)
		{
			cout<<9;
		}
		ch(l,r);
		for(int i=l;i<=r;i++)
		{
			if(op==1&&ans[i]==0) continue;
			if(ans[i]!=0) op=0;
			cout<<ans[i];
		}
	}
//	cout<<endl<<l<<' '<<r<<' '<<rr<<endl;
	for(int i=rr+1;i<=n;i++)
	{
		cout<<0;
	}
	cout<<endl;
}
int main()
{
	p[0]=1;
	for(int i=1;i<=20;i++)
	{
		p[i]=p[i-1]*10;
	}
	int t;
	cin>>t;
	while(t--)
	{
		sl();
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3432kb

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:

100000
10000
1000
100
10
1
900001
9900001
99900001
999900001
99999100000
9999910000
9999901000
9999900100
9999900010
9999900001
9000009999900001
99000009999900001
999000009999900001
99999999999999999900000000000000000
-1

result:

wrong answer 11th lines differ - expected: '10000000001', found: '99999100000'