QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#356723 | #5460. Sum of Numbers | louziyang | WA | 679ms | 5176kb | C++14 | 1.8kb | 2024-03-18 09:48:29 | 2024-03-18 09:48:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e5+7;
struct node{
string str;
}a,tot,mine,it;
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;
}
node operator + (const node &x,const node &y)
{
node ans;
ans.str="";
memset(l3,0,sizeof(l3));
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<=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;
}
while(l3[len3])
{
l3[len3+1]+=l3[len3]/10;
l3[len3]%=10;
++len3;
}
len3--;
while(l3[len3]>=10)
{
l3[len3+1]+=l3[len3]/10;
l3[len3]%=10;
len3++;
}
for(int i(len3);i>=1;--i)
{
ans.str+=l3[i]+'0';
if(ans.str[len3-i]<'0'||ans.str[len3-i]>'9')
printf("ccccccccccc");
}
return ans;
}
void dfs(node s,int x,int cnt)
{
if(x>=n||cnt>k)
return ;
if(cnt==k)
{
it.str=a.str.substr(x,MAXN);
mine=minu(mine,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);
it.str=a.str.substr(x,MAXN);
mine=minu(mine,it+s);
return ;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&k);
cin>>a.str;
mine.str=a.str;
len=n/(k+1);
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<<mine.str<<endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4744kb
input:
2 8 1 45455151 2 1 42
output:
9696 6
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 679ms
memory: 5176kb
input:
10 1301 6 56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...
output:
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...
result:
wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: 'cccccccccccccccccccccccccccccc...69097978667:27179252506798:1255'