結果

問題 No.2062 Sum of Subset mod 999630629
ユーザー 蜜蜂蜜蜂
提出日時 2022-08-26 21:34:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,574 bytes
コンパイル時間 4,721 ms
コンパイル使用メモリ 235,240 KB
実行使用メモリ 14,904 KB
最終ジャッジ日時 2024-04-21 23:34:04
合計ジャッジ時間 11,767 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//g++ 1.cpp -std=c++17 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;
 
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vst = vector<string>;
using vvst = vector<vst>;
 
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

using P = pair<int,vll>;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin>>n;

  ll sm=0;

  vi a(n);
  rep(i,0,n){
    cin>>a[i];
    sm+=a[i];
  }

  ll ans=sm;
  ans*=pow_mod(2,n-1,998244353);
  ans%=998244353;

  if(sm<999630629){
    cout<<ans<<endl;
    return 0;
  }

  int sz=sm-999630629; // 選ばないものの総和を sz 以下

  pq_small(P) que;

  vll init(1,1);

  rep(i,0,n){
    vll fps(a[i]+1,0);
    fps[0]=1;
    fps[a[i]]=1;
    init=convolution(init,fps);
    while(init.size()>sz+1){
      init.pop_back();
    }
  }

  ll sum=0;
  rep(i,0,sz+1){
    if(i>=init.size())break;
    sum+=init[i];
    sum%=998244353;
  }

  sum*=999630629;
  sum%=998244353;

  ans-=sum;
  ans%=998244353;
  if(ans<0)ans+=998244353;

  cout<<ans<<endl;
}
0