結果

問題 No.2513 Power Eraser
ユーザー 👑 amentorimaruamentorimaru
提出日時 2023-06-16 12:19:46
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 1,961 ms / 6,000 ms
コード長 1,867 bytes
コンパイル時間 4,607 ms
コンパイル使用メモリ 134,484 KB
実行使用メモリ 54,516 KB
最終ジャッジ日時 2023-10-20 21:02:59
合計ジャッジ時間 62,676 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 5 ms
4,348 KB
testcase_04 AC 30 ms
4,648 KB
testcase_05 AC 8 ms
4,348 KB
testcase_06 AC 44 ms
5,724 KB
testcase_07 AC 20 ms
4,508 KB
testcase_08 AC 36 ms
4,668 KB
testcase_09 AC 51 ms
5,732 KB
testcase_10 AC 34 ms
4,664 KB
testcase_11 AC 7 ms
4,348 KB
testcase_12 AC 26 ms
4,552 KB
testcase_13 AC 641 ms
26,092 KB
testcase_14 AC 1,387 ms
48,808 KB
testcase_15 AC 1,462 ms
49,916 KB
testcase_16 AC 850 ms
27,936 KB
testcase_17 AC 1,081 ms
30,664 KB
testcase_18 AC 1,383 ms
48,496 KB
testcase_19 AC 1,961 ms
54,480 KB
testcase_20 AC 721 ms
26,628 KB
testcase_21 AC 1,450 ms
49,556 KB
testcase_22 AC 1,446 ms
49,540 KB
testcase_23 AC 1,949 ms
54,516 KB
testcase_24 AC 1,889 ms
54,516 KB
testcase_25 AC 1,909 ms
54,516 KB
testcase_26 AC 1,870 ms
54,516 KB
testcase_27 AC 1,862 ms
54,516 KB
testcase_28 AC 1,853 ms
54,516 KB
testcase_29 AC 1,862 ms
54,516 KB
testcase_30 AC 1,822 ms
54,516 KB
testcase_31 AC 1,847 ms
54,516 KB
testcase_32 AC 1,848 ms
54,516 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 1,858 ms
54,516 KB
testcase_36 AC 1,842 ms
54,516 KB
7_evil_case_1.txt AC 4,323 ms
109,132 KB
7_evil_case_2.txt AC 4,336 ms
109,132 KB
7_evil_case_3.txt AC 4,273 ms
109,132 KB
7_evil_case_4.txt AC 4,258 ms
109,132 KB
7_evil_case_5.txt AC 4,312 ms
109,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include <atcoder/all>
using namespace std;
using ll = long long;
using namespace atcoder;
using mint2 = modint998244353;

vector<mint2> rev(vector<mint2>& f, ll mod) {
  vector<mint2> res = { mint2(1) / f[0] };
  ll t = 1;
  while (t < mod) {
    t *= 2;
    auto m = convolution(convolution(res, res), f);
    vector<mint2> nres(t);
    for (ll i = 0; i < t; i++) {      
      if (i < res.size())
        nres[i] += 2 * res[i];
      if (i < m.size())
        nres[i] += -m[i];
    }
    res = nres;
  }
  return res;
}

vector<mint2> div(vector<mint2>& f, vector<mint2>& g) {
  auto rf = f;
  auto rg = g;
  reverse(rf.begin(), rf.end());
  reverse(rg.begin(), rg.end());
  ll siz = f.size() - g.size() + 1;
  if (siz <= 0)
    return f;
  auto rv = rev(rg, siz);
  auto q = convolution(rf, rv);
  if (q.size() > siz)
    q.resize(siz);
  reverse(q.begin(), q.end());
  auto gq = convolution(g, q);
  auto res = f;
  for (ll i = 0; i < res.size(); i++) {    
    if (i < gq.size()) 
      res[i] -= gq[i];
  }
  while (res.back() == 0 && res.size() > 1)
    res.pop_back();
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  ll m = 1;
  while (m < n)
    m *= 2;
  vector<mint2> def = { 1 };
  vector<vector<mint2>> muls(m * 2, def);
  for (ll i = 0; i < n; i++)
    muls[i + m] = { a[i],-1 };
  for (ll i = m - 1; i > 0; i--)
    muls[i] = convolution(muls[i * 2], muls[i * 2 + 1]);
  
  mint2 ans = 1;
  vector<vector<mint2>> divs(m * 2, def);
  for (ll i = 2; i < m + n; i++) {
    queue<ll> que;
    divs[i] = convolution(divs[i], divs[i / 2]);
    if (i % 2)
      divs[i] = convolution(muls[i - 1], divs[i]);
    divs[i] = div(divs[i], muls[i]);
    if (m <= i)
      ans *= divs[i][0];
  }
  cout << ans.val() << endl;
  return 0;
}

0