记录编号 104333 评测结果 AAAAAAAATA
题目名称 超强的乘法问题 最终得分 90
用户昵称 Gravatarommy 是否通过 未通过
代码语言 C++ 运行时间 8.157 s
提交时间 2014-06-05 08:24:27 内存使用 2.04 MiB
显示代码纯文本
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
#define yy 1000000000
#define LL unsigned long long
char s1[151010],s2[151010];
LL A[101010],B[101010],C[101010],tmp;
int len_A,len_B,ll,st;
int main()
{
//	freopen("in.txt","r",stdin);
	freopen("bettermul.in","r",stdin);
	freopen("bettermul.out","w",stdout);
	
	scanf("%s%s",s1,s2);
	len_A=len_B=-1;
	ll=strlen(s1)-1;
	for(int i=ll;i>=0;--i)
	{
		if((ll-i)%9==0) ++len_A,tmp=1;
		A[len_A]+=(s1[i]-'0')*tmp;
		tmp*=10;
	}
	ll=strlen(s2)-1;
	for(int i=ll;i>=0;--i)
	{
		if((ll-i)%9==0) ++len_B,tmp=1;
		B[len_B]+=(s2[i]-'0')*tmp;
		tmp*=10;
	}
	
	for(register int add=0;add<=len_A+len_B;++add)
		for(register int i=0;i<=len_A && i<=add;i+=15)
		{
			C[add]+=A[i]*B[add-i] + A[i+1]*B[add-i-1]
			      + A[i+2]*B[add-i-2]+ A[i+3]*B[add-i-3]+ A[i+4]*B[add-i-4]
			      + A[i+5]*B[add-i-5]+ A[i+6]*B[add-i-6]+ A[i+7]*B[add-i-7]
				  + A[i+8]*B[add-i-8]+ A[i+9]*B[add-i-9]+ A[i+10]*B[add-i-10]
			      + A[i+11]*B[add-i-11]+ A[i+12]*B[add-i-12]+ A[i+13]*B[add-i-13]
			      + A[i+14]*B[add-i-14];

			if(C[add]>yy)
			{
				C[add+1]+=C[add]/yy;
				C[add]%=yy;
			}
		}
	
	/*
	for(register int i=0;i<=len_A;++i)
		for(register int j=0;j<=len_B;++j)
		{
			C[i+j]+=A[i]*B[j]; //cout<<A[i]<<" * "<<B[j]<<" "<<C[i+j]<<endl;
			//cout<<"~"<<C[2]<<" "<<C[3]<<endl;
			if(C[i+j]>=yy)
			{
				C[i+j+1]+=C[i+j]/yy;
				C[i+j]%=yy;
				//if(C[i+j+1]>=yy) cout<<"!"<<endl;
			}
			//cout<<"| "<<C[2]<<" "<<C[3]<<endl;
		}
	*/
	st=len_A+len_B+1;
	if(!C[st]) --st;
	printf("%lld",C[st]);
	for(int i=st-1;i>=0;--i)
		printf("%09lld",C[i]);
	return 0;
}