QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#534059#8340. 3 Sumtraining_233#Compile Error//C++143.4kb2024-08-26 20:09:482024-08-26 20:09:49

Judging History

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

  • [2024-09-20 10:20:30]
  • hack成功,自动添加数据
  • (/hack/848)
  • [2024-08-26 20:09:49]
  • 评测
  • [2024-08-26 20:09:48]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
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(a[i]+a[j]);
            if(mp.count(res))
                ans+=mp[res];
        }
        ++mp[solve(M-a[i])];
    }
    cout<<ans<<'\n';
    cout.flush();
    return 0;
}

Details

answer.code:55:1: error: ‘set’ does not name a type
   55 | set<num> st;
      | ^~~