QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#357409 | #5460. Sum of Numbers | louziyang | WA | 3ms | 72952kb | C++14 | 2.2kb | 2024-03-18 21:04:29 | 2024-03-18 21:04:29 |
Judging History
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 y;
if(y.str.size()==0)
return x;
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 l,int cnt)
{
if(l==0||l>=n)
return ;
if(x>=n||cnt>k)
return ;
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(cnt==k)
{
it.str=a.str.substr(x,n-x);
minx=minu(minx,it+s);
return ;
}
it.str=a.str.substr(x,l-1);
dfs(s+it,x+l-1,l-1,cnt+1);
it.str=a.str.substr(x,l);
dfs(s+it,x+l,l,cnt+1);
it.str=a.str.substr(x,l+1);
dfs(s+it,x+l+1,l+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="";
for(int i(1);i<=n;++i)
{
if((k+1)*i+k*(k+1)/2>=n&&(k+1)*i<=len+k/2+1)
{
tot.str=a.str.substr(0,i);
dfs(tot,i,i,1);
}
}
// tot.str=a.str.substr(0,len);
// dfs(tot,len,len,1);
// tot.str=a.str.substr(0,len+1);
// dfs(tot,len+1,len+1,1);
cout<<minx.str<<endl;
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 72952kb
input:
2 8 1 45455151 2 1 42
output:
45455151 6
result:
wrong answer 1st lines differ - expected: '9696', found: '45455151'