QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#356709 | #5460. Sum of Numbers | louziyang | WA | 572ms | 5056kb | C++14 | 1.6kb | 2024-03-18 09:42:55 | 2024-03-18 09:42:56 |
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--;
for(int i(len3);i>=1;--i)
ans.str+=l3[i]+'0';
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4428kb
input:
2 8 1 45455151 2 1 42
output:
9696 6
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 572ms
memory: 5056kb
input:
10 1301 6 56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...
output:
1861837555106640794797067737879913860686764066159587941287350938727749577629356630564:343534145264385075:3808735990934:0822519207:06517442350857537792:7221969097978667:27179252506798:1255 13308978966559747740355863:65448:743484283504833641127111042783648306345794:8738245622889343640965465374923673:1...
result:
wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '186183755510664079479706773787...69097978667:27179252506798:1255'