QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#534058#8340. 3 Sumtraining_233#TL 339ms15396kbC++143.3kb2024-08-26 20:08:272024-08-26 20:08:27

Judging History

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

  • [2024-09-20 10:20:30]
  • hack成功,自动添加数据
  • (/hack/848)
  • [2024-08-26 20:08:27]
  • 评测
  • 测评结果:TL
  • 用时:339ms
  • 内存:15396kb
  • [2024-08-26 20:08:27]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<set>
using namespace std;
const long long mod=1e18;
int n,m,ans,cnt;
long long base;
string s;
struct num
{
    int len;
    long long a[1501];
    num()
    {
        len=0;
        memset(a,0,sizeof a);
    }
    inline void init(string s)
    {
        reverse(s.begin(),s.end());
        while(s.length()%18)
            s.push_back('0');
        len=s.length()/18;
        for(int i=len;i>=1;--i)
            for(int j=1;j<=18;++j)
            {
                a[i]=a[i]*10+s.back()-'0';
                s.pop_back();
            }
    }
    bool operator <(const num &other) const
    {
        if(len^other.len)
            return len<other.len;
        for(int i=len;i>=1;--i)
            if(a[i]^other.a[i])
                return a[i]<other.a[i];
        return 0;
    }
    bool operator ==(const num &other) const
    {
        if(len^other.len)
            return 0;
        for(int i=len;i>=1;--i)
            if(a[i]^other.a[i])
                return 0;
        return 1;
    }
}a[501],tmp,M;
map<num,int> mp;
set<num> st;
inline num operator +(const num &x,const num &y)
{
    num res;
    res.len=max(x.len,y.len);
    long long d=0;
    for(int i=1;i<=res.len;++i)
    {
        res.a[i]=d;
        if(res.len<=x.len)
            res.a[i]+=x.a[i];
        if(res.len<=y.len)
            res.a[i]+=y.a[i];
        d=res.a[i]/mod;
        res.a[i]%=mod;
    }
    while(d)
    {
        res.a[++res.len]=d;
        d=res.a[res.len]/mod;
        res.a[res.len]%=mod;
    }
    return res;
}
inline num operator -(const num &x,const num &y)
{
    num res;
    res.len=x.len;
    long long d=0;
    for(int i=1;i<=res.len;++i)
    {
        res.a[i]=x.a[i]-d;
        if(i<=y.len)
            res.a[i]-=y.a[i];
        d=0;
        if(res.a[i]<0)
        {
            res.a[i]+=mod;
            d=mod;
        }
    }
    while(res.len&&!res.a[res.len])
        --res.len;
    return res;
}
inline num solve(num x)
{
    while(!(x<M))
    {
        if(x==M)
        {
            x.len=0;
            return x;
        }
        tmp.len=M.len;
        for(int i=1;i<tmp.len;++i)
            tmp.a[i]=x.a[i];
        tmp.a[tmp.len]=x.a[tmp.len]%base;
        for(int i=tmp.len;i<=x.len;++i)
            x.a[i-tmp.len+1]=x.a[i]/base+x.a[i+1]%base*(mod/base);
        x.len-=tmp.len-1;
        while(!x.a[x.len])
            --x.len;
        x=tmp+x;
    }
    while(x.len&&!x.a[x.len])
        --x.len;
    return x;
}
inline void init()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
}
int main()
{
    init();
    cin>>n>>m;
    cnt=m%18;
    base=1;
    for(int i=1;i<=cnt;++i)
        base*=10;
    for(int i=1;i<=m;++i)
        s.push_back('9');
    M.init(s);
    for(int i=1;i<=n;++i)
    {
        cin>>s;
        a[i].init(s);
        a[i]=solve(a[i]);
    }
    for(int i=1;i<=n;++i)
        for(int j=1;j<=n;++j)
            ans+=!solve(a[i]+a[i]+a[j]).len;
    for(int i=1;i<=n;++i)
    {
        for(int j=i+1;j<=n;++j)
        {
            num res=solve(M-solve(a[i]+a[j]));
            if(mp.count(res))
                ans+=mp[res];
        }
        ++mp[a[i]];
    }
    cout<<ans<<'\n';
    cout.flush();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 1
0
1
10
17

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 339ms
memory: 15396kb

input:

500 859
7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Time Limit Exceeded

input:

500 17336
11871159223687829792235950161360414494835561698697083734067767137675360383685281188659130037014315194336852912974981311847615186584425521253435544161148142093848317807514306269134525728824246028271538975878964854109909073587561782234855194213461696355772305598026008223090250526997551814628...

output:


result: