結果

問題 No.1857 Gacha Addiction
ユーザー 蜜蜂蜜蜂
提出日時 2021-12-31 19:16:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 981 ms / 6,000 ms
コード長 1,657 bytes
コンパイル時間 4,441 ms
コンパイル使用メモリ 250,164 KB
実行使用メモリ 32,480 KB
最終ジャッジ日時 2023-09-14 14:23:19
合計ジャッジ時間 36,363 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 10 ms
4,376 KB
testcase_05 AC 10 ms
4,376 KB
testcase_06 AC 11 ms
4,380 KB
testcase_07 AC 11 ms
4,376 KB
testcase_08 AC 10 ms
4,380 KB
testcase_09 AC 253 ms
11,972 KB
testcase_10 AC 251 ms
11,596 KB
testcase_11 AC 251 ms
11,904 KB
testcase_12 AC 254 ms
12,072 KB
testcase_13 AC 255 ms
11,996 KB
testcase_14 AC 981 ms
31,280 KB
testcase_15 AC 976 ms
29,880 KB
testcase_16 AC 969 ms
30,880 KB
testcase_17 AC 958 ms
30,580 KB
testcase_18 AC 959 ms
31,068 KB
testcase_19 AC 947 ms
29,892 KB
testcase_20 AC 954 ms
30,292 KB
testcase_21 AC 954 ms
30,448 KB
testcase_22 AC 951 ms
31,204 KB
testcase_23 AC 958 ms
30,308 KB
testcase_24 AC 957 ms
29,824 KB
testcase_25 AC 977 ms
30,696 KB
testcase_26 AC 971 ms
32,480 KB
testcase_27 AC 965 ms
29,644 KB
testcase_28 AC 968 ms
30,888 KB
testcase_29 AC 967 ms
31,396 KB
testcase_30 AC 967 ms
30,884 KB
testcase_31 AC 961 ms
30,828 KB
testcase_32 AC 965 ms
29,956 KB
testcase_33 AC 972 ms
30,832 KB
testcase_34 AC 968 ms
31,364 KB
testcase_35 AC 968 ms
30,276 KB
testcase_36 AC 965 ms
30,620 KB
testcase_37 AC 973 ms
29,696 KB
testcase_38 AC 954 ms
30,596 KB
testcase_39 AC 264 ms
12,900 KB
testcase_40 AC 276 ms
13,084 KB
testcase_41 AC 370 ms
16,292 KB
testcase_42 AC 72 ms
6,172 KB
testcase_43 AC 751 ms
27,572 KB
testcase_44 AC 848 ms
29,184 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:56:10: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   56 |     auto [sz1,A,B]=que.top();
      |          ^
main.cpp:58:10: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   58 |     auto [sz2,a,b]=que.top();
      |          ^
main.cpp:78:8: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   78 |   auto [sz,q,r]=que.top();
      |        ^

ソースコード

diff #

//g++ 2.cpp -std=c++14 -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 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())

// size pi/sx+1 (pi/s)^2x
using P = tuple<int,vll,vll>;

constexpr ll mod = 998244353;

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

  int n;
  ll s;
  cin>>n>>s;

  ll inv_s=pow_mod(s,mod-2,mod);

  pq_small(P) que;

  rep(i,0,n){
    ll p;
    cin>>p;
    p*=inv_s;
    p%=mod;
    que.push({1,{1,p},{0,(p*p)%mod}});
  }

  while(que.size()>1){
    auto [sz1,A,B]=que.top();
    que.pop();
    auto [sz2,a,b]=que.top();
    que.pop();

    vll x=convolution(A,a);
    vll y=convolution(A,b);
    vll z=convolution(B,a);

    rep(i,0,z.size()){
      if(i<y.size()){
        y[i]+=z[i];
        y[i]%=mod;
      }
      else{
        y.emplace_back(z[i]);
      }
    }

    que.push({sz1+sz2,x,y});
  }

  auto [sz,q,r]=que.top();

  ll ans=0;
  ll fractal=2;
  rep(i,1,r.size()){
    ans+=r[i]*fractal;
    ans%=mod;
    fractal*=i+2;
    fractal%=mod;
  }

  cout<<ans<<endl;
}
0