QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#710094#5460. Sum of Numbers123456zmy#TL 0ms3864kbC++171.4kb2024-11-04 18:38:102024-11-04 18:38:15

Judging History

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

  • [2024-11-04 18:38:15]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3864kb
  • [2024-11-04 18:38:10]
  • 提交

answer

#include<bits/stdc++.h>
#define pp printf("\n")
#define pb push_back
using namespace std;
int T,n,k,o,a,l;
char s[200001];
int ans[200001],c[200001],d[200001],la,lc,ld;
int b[10];
void jia()
{
    for (int i=1;i<=max(lc,ld);i++)
    {
        d[i]=d[i]+c[i];
        d[i+1]+=d[i]/10;
        d[i]%=10;
    }
    ld=max(lc,ld);
    ld+=(d[ld+1]>0);
}
void minn()
{
    int bz=0;
    if (ld>la)return;
    for (int i=la;i>=1;i--)if (ans[i]!=d[i])
    {
        bz=(ans[i]>d[i]);
        break;
    }
    if (ld<la||(ld==la&&bz==1))
    {
        la=ld;
        for (int i=1;i<=la;i++)ans[i]=d[i];
    }
}
void dg(int x)
{
    if (x==k)
    {
        b[x+1]=n;
        if (n-b[x]+1>=a+3)return;
        for (int i=1;i<=k+1;i++)
        {
            for (int j=b[i];j>b[i-1];j--)c[++lc]=(s[j]-'0');
            jia();
            for (int j=1;j<=lc;j++)c[j]=0;
            lc=0;
        }
        minn();
        for (int j=1;j<=ld;j++)d[j]=0;
        ld=0;
        return;
    }
    for (int i=max(1,a-1);i<=(a+2);i++)
    {
        if (b[x]+i<=n)
        {
            b[x+1]=b[x]+i;
            dg(x+1);
        }
    }
}
int main()
{
    scanf("%d",&T);
    while (T--)
    {
        scanf("%d %d",&n,&k);
        scanf("%s",s+1);
        la=n+1;
        b[l=0]=0;
        o=n%(k+1);
        a=n/(k+1);
        dg(0);
        for (int i=la;i>=1;i--)printf("%d",ans[i]);pp;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3864kb

input:

2
8 1
45455151
2 1
42

output:

9696
6

result:

ok 2 lines

Test #2:

score: -100
Time Limit Exceeded

input:

10
1301 6
56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...

output:

2861837555106640794797067737879913860686764066159587941287350938727749577629356630565034353414526438507603808735990935008225192080065174423508575377930722196909797866802717925250679901255
1330897896655974774035586406544907434842835048336411271110427836483063457950873824562288934364096546537492367401...

result: