結果

問題 No.2513 Power Eraser
ユーザー 👑 amentorimaruamentorimaru
提出日時 2023-06-16 13:32:43
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 4,850 ms / 6,000 ms
コード長 2,211 bytes
コンパイル時間 3,039 ms
コンパイル使用メモリ 134,408 KB
実行使用メモリ 34,744 KB
最終ジャッジ日時 2023-10-20 21:04:26
合計ジャッジ時間 68,939 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
34,744 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 7 ms
4,348 KB
testcase_04 AC 51 ms
4,348 KB
testcase_05 AC 11 ms
4,348 KB
testcase_06 AC 77 ms
4,492 KB
testcase_07 AC 33 ms
4,348 KB
testcase_08 AC 63 ms
4,348 KB
testcase_09 AC 99 ms
4,752 KB
testcase_10 AC 62 ms
4,348 KB
testcase_11 AC 10 ms
4,348 KB
testcase_12 AC 47 ms
4,348 KB
testcase_13 AC 1,457 ms
15,120 KB
testcase_14 AC 3,371 ms
27,332 KB
testcase_15 AC 3,499 ms
27,860 KB
testcase_16 AC 1,896 ms
16,356 KB
testcase_17 AC 2,315 ms
17,192 KB
testcase_18 AC 3,401 ms
27,284 KB
testcase_19 AC 4,638 ms
30,348 KB
testcase_20 AC 1,639 ms
15,524 KB
testcase_21 AC 3,536 ms
27,720 KB
testcase_22 AC 3,494 ms
27,700 KB
testcase_23 AC 4,584 ms
30,372 KB
testcase_24 AC 4,837 ms
30,372 KB
testcase_25 AC 4,615 ms
30,372 KB
testcase_26 AC 4,654 ms
30,372 KB
testcase_27 AC 4,686 ms
30,372 KB
testcase_28 AC 4,547 ms
30,372 KB
testcase_29 AC 4,842 ms
30,372 KB
testcase_30 AC 4,833 ms
30,372 KB
testcase_31 AC 4,850 ms
30,372 KB
testcase_32 AC 4,832 ms
30,372 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 4,840 ms
30,372 KB
testcase_36 AC 4,833 ms
30,372 KB
7_evil_case_1.txt TLE -
7_evil_case_2.txt TLE -
7_evil_case_3.txt TLE -
7_evil_case_4.txt TLE -
7_evil_case_5.txt TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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(res, res);
    m = convolution(m, 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;
  auto q = convolution(rf, rev(rg, 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;
}

ll n;
vector<ll> a;

mint2 solve2(ll l1, ll l2, ll d) {
  ll m = 1;
  while (m < d) {
    m *= 2;
  }
  vector<ll> a1(d), a2(d);
  for (ll i = 0; i < d; i++) {    
    a1[i] = a[l1 + i];
    a2[i] = a[l2 + i];
  }
  vector<mint2> def = { 1 };
  vector<vector<mint2>> f1(m * 2, def), f2(m * 2, def);
  for (ll i = 0; i < d; i++) {
    f1[i + m] = { a1[i],-1 };
    f2[i + m] = { a2[i],-1 };
  }
  for (ll i = m - 1; i >= 1; i--) {
    f1[i] = convolution(f1[i * 2], f1[i * 2 + 1]);
    f2[i] = convolution(f2[i * 2], f2[i * 2 + 1]);
  }
  f1[1] = div(f1[1], f2[1]);
  for (ll i = 2; i < 2 * m; i++) {
    auto& p = f1[i / 2];
    if (f2[i].size() != 1)
      f1[i] = div(p, f2[i]);
  }

  mint2 res = 1;
  for (ll i = 0; i < d; i++)
    res *= f1[i + m][0];
  return res;
}

mint2 solve(ll l, ll r) {
  if (l >= r - 1)
    return 1;
  mint2 res = 1;
  ll d = (r - l) / 2;
  res *= solve2(l, r - d, d);
  res *= solve(l, r - d);
  res *= solve(l + d, r);
  return res;
}

void solve() {
}


int main() {
  cin >> n;
  a.resize(n);
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  mint2 ans = 1;
  cout << solve(0, n).val();
  return 0;
}

0