QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#506767#5460. Sum of Numberscocoa_chan#WA 249ms9196kbC++172.9kb2024-08-05 21:30:422024-08-05 21:30:42

Judging History

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

  • [2024-08-05 21:30:42]
  • 评测
  • 测评结果:WA
  • 用时:249ms
  • 内存:9196kb
  • [2024-08-05 21:30:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll e,ee,n,m,i,j,k,l,r,x,y,z,w,s,t,a[1100000],b[1100000],siz,normalsize;
vector<ll> ans;
vector<ll> add(vector<ll> a,vector<ll> b)
{
    vector<ll> v;
    v.resize(max(a.size(),b.size())+1);
    ll i;
    for(i=0;i<a.size();i++)
        v[i]+=a[i];
    for(i=0;i<b.size();i++)
        v[i]+=b[i];
    for(i=0;i<v.size();i++)
    {
        if(v[i]>10)
        {
            v[i+1]+=v[i]/10;
            v[i]%=10;
        }
    }
    return v;
}
vector<ll> interval(ll x,ll y)
{
    ll i,s=0;
    vector<ll> v;
    v.resize(y-x+1);
    for(i=y;i>=x;i--)
    {
        v[s]+=a[i];
        s++;
    }
    return v;
}
ll bigger(vector<ll> a,vector<ll> b)
{
    if(a.empty())
        return 1;
    if(b.empty())
        return 0;
    ll i;
    if(a.size()>b.size())
    {
        for(i=ll(a.size())-1;i>=b.size();i--)
        {
            if(a[i])
                return 1;
        }
    }
    if(b.size()<a.size())
    {
        for(i=ll(b.size())-1;i>=a.size();i--)
        {
            if(b[i])
                return 0;
        }
    }
        for(i=min(b.size(),a.size())-1;i>=0;i--)
        {
            if(a[i]<b[i])
                return 0;
            if(a[i]>b[i])
                return 1;
        }
        return 1;
}
void show(vector<ll> a)
{
    return;
    ll i;
    for(i=0;i<a.size();i++)
        printf("%lld ",a[i]);
    printf("\n");
}
vector<ll> f(ll x,ll y,ll z)
{
    if(z==0)
    {
       // printf("(%lld,%lld,%lld):",x,y,z);
        show(interval(x,y));
        return interval(x,y);
    }
    vector<ll> u;
    vector<ll> v1,v2,v3;
    if(normalsize>1&&(y-(x+normalsize-1)+1)>z-1)
    v1=add(f(x+normalsize-1,y,z-1),interval(x,x+normalsize-2));
   // printf("!(%lld)",v1.size());
    if(y-(x+normalsize)+1>z-1)
    {
        v2=add(f(x+normalsize,y,z-1),interval(x,x+normalsize-1));
    }
    if(y-(x+normalsize+1)+1>z-1)
    {
        v3=add(f(x+normalsize+1,y,z-1),interval(x,x+normalsize));
    }
    show(v1);
    show(v2);
    show(v3);
   // printf("?");
    if(bigger(v1,v2))
        {swap(v1,v2);
        //printf("(!)");
        }
    if(bigger(v1,v3))
        swap(v3,v1);
    return v1;
}
int main()
{
    scanf("%lld",&e);
    for(ee=0;ee<e;ee++)
    {
        scanf("%lld %lld",&n,&k);
        siz=n/(k+1)+10;
        normalsize=(n+k)/(k+1);
        //printf("(%lld,%lld)\n",siz,normalsize);
        for(i=1;i<=n;i++)
        {
            scanf("%01lld",&a[i]);
        }
        show(interval(5,8));
        ans=f(1,n,k);
        //printf("(%lld)",ans.size());
        x=0;
        for(i=ll(ans.size())-1;i>=0;i--)
        {
            if(ans[i])
                x=1;
            if(x==0)
                continue;
            printf("%lld",ans[i]);
        }
        printf("\n");
}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
8 1
45455151
2 1
42

output:

9696
6

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 249ms
memory: 9196kb

input:

10
1301 6
56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...

output:

28618375541010663107947961067737879913851068676310661595879412873410938727749577629356621056410343534145264384107510371087359810934910822519110791065174423410857537792107221968109797866710271792524106798101255
132108978966559747731035586310654481074348428341048336411261010101042783648210634579508738...

result:

wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '286183755410106631079479610677...9797866710271792524106798101255'