結果

問題 No.2062 Sum of Subset mod 999630629
ユーザー gs15120gs15120
提出日時 2022-09-16 00:18:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,458 bytes
コンパイル時間 2,573 ms
コンパイル使用メモリ 184,600 KB
実行使用メモリ 4,600 KB
最終ジャッジ日時 2023-08-22 17:41:39
合計ジャッジ時間 6,058 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,384 KB
testcase_06 AC 3 ms
4,392 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 12 ms
4,380 KB
testcase_09 AC 10 ms
4,380 KB
testcase_10 AC 9 ms
4,420 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 9 ms
4,380 KB
testcase_24 AC 10 ms
4,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lll long long//__int128
#define pii pair<int,int>
//#define f first
//#define s second
# define PI 3.14159265358979323846
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

struct chash_key
{
    ll operator()(pii x) const { return (ll)x.first*1000000000   + x.second; }
};
//gp_hash_table<pii,int,chash_key> hs[2],p[2];

//gp_hash_table<ll,int> dp;

struct P
{
    int x,y;
    bool operator <(const P &a) const
    {

        //if(y!=a.y)
        //return y<a.y;

        return y>a.y;
    }
    bool operator <=(const P &a)const
    {
        return (x<=a.x&&y<=a.y);
    }
    P operator +(const P &a)const
    {
        return {x+a.x,y+a.y};
    }

};

const ll mod=998244353,pp=999630629;
ll tw[111111];
int cnt[11111],a;
ll x=0;

int main()
{
    tw[0]=1;

    for(int t=1;t<=100000;t++)
    {
        tw[t]=tw[t-1]*2;
        if(tw[t]>=mod) tw[t]-=mod;
    }
    scanf("%d",&a);
    for(int t=1;t<=a;t++)
    {
        int s;
        scanf("%d",&s);
        cnt[s]++;
        x+=s;
    }
    ll ans=0;
    ll d=0;
    if(x>=pp) d=1;

    for(int t=1;t<=10000;t++)
    {
        ans+=tw[a-1]*t%mod*cnt[t]%mod;
        if(ans>=mod) ans-=mod;

        if(x-t>=pp) d+=cnt[t];

        if(x-t*2>=pp)
        {
            d+=(ll)cnt[t]*(cnt[t]-1)/2;
        }
        if(x-t*3>=pp)
        {
            d+=(ll)cnt[t]*(cnt[t]-1)*(cnt[t]-2)/6;
        }
    }
    for(int t=1;t<=10000;t++)
        cnt[t]+=cnt[t-1];

    for(int t=10000;t>=1;t--)
    {
        if(x-t*2>=pp)
        {
            d+=(ll)(cnt[t]-cnt[t-1])*cnt[t-1];
            //d+=(ll)(cnt[t]-1-cnt[t-1])*(cnt[t]-cnt[t-1]);
        }
        else if(x-t>pp)
        {
            d+=(ll)(cnt[t]-cnt[t-1])*cnt[x-t-pp];
        }
    }
    for(int i=10000;i>=1;i--)
        for(int j=i;j>=1;j--)
    if(x-i-j>pp)
    {
        if(x-i-j-pp<j)
        {
            if(i!=j) d+=(ll)(cnt[i]-cnt[i-1])*(cnt[j]-cnt[j-1]-1)/2*cnt[x-i-j-pp];
            else d+=(ll)(cnt[i]-cnt[i-1])*(cnt[j]-cnt[j-1])*cnt[x-i-j-pp];
        }
        else if(i!=j)
        {
            d+=(ll)(cnt[i]-cnt[i-1])*(cnt[j]-cnt[j-1])*cnt[j-1];
            d+=(ll)(cnt[i]-cnt[i-1])*(cnt[j]-cnt[j-1])*(cnt[j]-cnt[j-1]-1)/2;
        }
        else
        {
            d+=(ll)(cnt[i]-cnt[i-1])*(cnt[j]-cnt[j-1]-1)/2*cnt[i-1];
        }
    }
    d%=mod;

    //ans-=d*pp%mod;
    if(ans<0) ans+=mod;
    printf("%lld",ans);
}
0