QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#357272#5460. Sum of NumberslouziyangWA 4ms73392kbC++142.0kb2024-03-18 19:52:542024-03-18 19:52:55

Judging History

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

  • [2024-03-18 19:52:55]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:73392kb
  • [2024-03-18 19:52:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e5+7;
struct node{
	string str;
}a,tot,minx,it,vis[11][MAXN];
int l1[MAXN],l2[MAXN],l3[MAXN],n,k,len;
node minu(node x,node y)
{
	if(x.str.size()<y.str.size())
		return x;
	if(x.str.size()>y.str.size())
		return y;
	if(x.str<y.str)
		return x;
	else
		return y;
}
bool operator == (const node &x,const node &y)
{
	return x.str==y.str;
}
node operator + (const node &x,const node &y)
{
	if(x.str.size()==0)
		return x;
	if(y.str.size()==0)
		return y;
	node ans;
	ans.str="";
	int len1=x.str.size(),len2=y.str.size(),len3;
	for(int i(1);i<=len1;++i)
		l1[len1-i+1]=x.str[i-1]-'0';
	for(int i(1);i<=len2;++i)
		l2[len2-i+1]=y.str[i-1]-'0';
	len3=max(len1,len2);
	for(int i(1);i<=len3+2;++i)
		l3[i]=0;
	for(int i(1);i<=max(len1,len2);++i)
	{
		if(i>len1)
		l1[i]=0;
		if(i>len2)
		l2[i]=0;
		l3[i]+=(l1[i]+l2[i])%10;
		l3[i+1]+=(l1[i]+l2[i])/10;
	}
	for(int i(1);i<=len3;++i)
	{
		l3[i+1]+=l3[i]/10;
		l3[i]%=10;
		if(l3[i+1])
			len3=max(i+1,len3);
	}
	for(int i(len3);i>=1;--i)
		ans.str+=l3[i]+'0';
	return ans;
}
void dfs(node s,int x,int cnt)
{
	if(vis[cnt][x].str.size()==0)
		vis[cnt][x]=s;
	else
	{
		if(minu(vis[cnt][x],s)==vis[cnt][x])
			return ;
		vis[cnt][x]=s;
	}
	if(x>=n||cnt>k)
		return ;
	if(cnt==k)
	{
		it.str=a.str.substr(x,n-x);
		minx=minu(minx,it+s);
		return ;
	}
	it.str=a.str.substr(x,len-1);
	dfs(s+it,x+len-1,cnt+1);
	it.str=a.str.substr(x,len);
	dfs(s+it,x+len,cnt+1);
	it.str=a.str.substr(x,len+1);
	dfs(s+it,x+len+1,cnt+1);
	return ;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n>>k;
		cin>>a.str;
		minx.str=a.str;
		len=n/(k+1);
		for(int i(1);i<=k+1;++i)
			for(int j(0);j<=n;++j)
				vis[i][j].str="";
		tot.str=a.str.substr(0,len-1);
		dfs(tot,len-1,1);
		tot.str=a.str.substr(0,len);
		dfs(tot,len,1);
		tot.str=a.str.substr(0,len+1);
		dfs(tot,len+1,1);
		cout<<minx.str<<endl;
	}
	return 0;
 } 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 73392kb

input:

2
8 1
45455151
2 1
42

output:

9696


result:

wrong answer 2nd lines differ - expected: '6', found: ''