結果

問題 No.2062 Sum of Subset mod 999630629
ユーザー 蜜蜂蜜蜂
提出日時 2022-08-26 21:32:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,751 bytes
コンパイル時間 5,059 ms
コンパイル使用メモリ 239,624 KB
実行使用メモリ 818,124 KB
最終ジャッジ日時 2024-04-21 23:31:12
合計ジャッジ時間 9,269 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 11 ms
5,376 KB
testcase_09 AC 9 ms
5,376 KB
testcase_10 AC 9 ms
5,376 KB
testcase_11 MLE -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:69:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   69 |     auto [s1,fps1]=que.top();
      |          ^
main.cpp:71:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   71 |     auto [s2,fps2]=que.top();
      |          ^
main.cpp:80:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   80 |   auto [s,fps]=que.top();
      |        ^

ソースコード

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;

  rep(i,0,n){
    vll fps(a[i]+1,0);
    fps[0]=1;
    fps[a[i]]=1;
    que.push({a[i]+1,fps});
  }

  while(que.size()>1){
    auto [s1,fps1]=que.top();
    que.pop();
    auto [s2,fps2]=que.top();
    que.pop();
    vll fps=convolution(fps1,fps2);
    while(fps.size()>sz+1){
      fps.pop_back();
    }
    que.push({fps.size(),fps});
  }

  auto [s,fps]=que.top();
  ll sum=0;
  rep(i,0,sz+1){
    if(i>=s)break;
    sum+=fps[i];
    sum%=998244353;
  }

  sum*=999630629;
  sum%=998244353;

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

  cout<<ans<<endl;
}
0