結果
| 問題 |
No.2062 Sum of Subset mod 999630629
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-16 00:24:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,506 bytes |
| コンパイル時間 | 3,241 ms |
| コンパイル使用メモリ | 189,264 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-17 18:15:29 |
| 合計ジャッジ時間 | 9,756 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 WA * 17 |
ソースコード
#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;
}
d%=mod;
}
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];
}
d%=mod;
}
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;
}
//d%=mod;
ans-=d*pp%mod;
if(ans<0) ans+=mod;
printf("%lld",ans);
}