QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#613075#8932. BingotreasuresgcWA 0ms3772kbC++231.4kb2024-10-05 13:31:522024-10-05 13:32:17

Judging History

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

  • [2024-10-05 13:32:17]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3772kb
  • [2024-10-05 13:31:52]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int Len(int x)
{
	int len=0;
	while(x) len++,x/=10;
	return len;
}
int H[2000005];
inline void solve()
{
	string n;
	int m;
	cin>>n>>m;
	reverse(n.begin(),n.end());
	for(int i=0;i<=15;i++) n+='0';
	reverse(n.begin(),n.end());
	int ans=0;
	for(int i=0;i<n.size();i++) ans=ans*10+n[i]-48,ans%=m;
	ans=m-ans;
	if(ans==0) ans=m;

	int lenm=Len(m);
	int Mm=pow(10,lenm);
	int G=1;
	int bak=1;
	for(int i=n.size()-1;i>=lenm-1;i--,G=(G<1000000000?G*10:G))
	{
		int s=0;
		for(int j=i-lenm+1;j<=i;j++)s=s*10+n[j]-48;

		if(G==1000000000)
		{
			if(s==m)
			{
				if(bak>1) ans=1;
			}
			else
			{
				if(m-s==1 || (Mm+m-s)==1)
				{
					ans=min(ans,bak);
				}
			}

			if(n[i]!='9') bak=m+5;
			continue;
		}

		if(m==s)
		{
			if(bak!=1)
			{
				ans=1;
				break;
			}
		}

		int turn=(m-s);
		if(turn<=0) turn+=Mm;
		turn--;

		 cout<<turn<<" "<<bak<<" "<<s<<" "<<m<<" "<<G<<endl;

		ans=min(ans,turn*G+bak);

		bak=bak+(9-(n[i]-48))*G;	
	}
	// cout<<ans<<" ";

	for(int i=0;i<n.size();i++) H[i]=n[n.size()-i-1]-48;
	H[0]+=ans;
	for(int i=0;i<n.size();i++)
	{
		H[i+1]+=H[i]/10;
		H[i]%=10;
	}
	bool d0=1;
	for(int i=n.size();i>=0;i--)
	{
		if(H[i])
		{
			d0=0;
			cout<<H[i];
		}
		else if(!d0) cout<<H[i];
	}
	cout<<endl;	
}
signed main(){
	int T;
	cin>>T;
	while(T--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3772kb

input:

6
7 3
12 3
9 10
249 51
1369 37
2 1

output:

5 1 7 3 1
2 3 0 3 10
2 93 0 3 100
2 993 0 3 1000
2 9993 0 3 10000
2 99993 0 3 100000
2 999993 0 3 1000000
2 9999993 0 3 10000000
2 99999993 0 3 100000000
9
0 1 2 3 1
1 8 1 3 10
2 88 0 3 100
2 988 0 3 1000
2 9988 0 3 10000
2 99988 0 3 100000
2 999988 0 3 1000000
2 9999988 0 3 10000000
2 99999988 0 3 ...

result:

wrong answer 1st lines differ - expected: '9', found: '5 1 7 3 1'