結果

問題 No.2513 Power Eraser
ユーザー SSRSSSRS
提出日時 2023-10-20 22:16:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,619 bytes
コンパイル時間 4,195 ms
コンパイル使用メモリ 253,356 KB
実行使用メモリ 27,608 KB
最終ジャッジ日時 2024-09-20 19:38:39
合計ジャッジ時間 52,231 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
12,196 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 7 ms
5,376 KB
testcase_04 AC 62 ms
5,376 KB
testcase_05 AC 12 ms
5,376 KB
testcase_06 AC 93 ms
5,376 KB
testcase_07 AC 36 ms
5,376 KB
testcase_08 AC 78 ms
5,376 KB
testcase_09 AC 108 ms
5,376 KB
testcase_10 AC 72 ms
5,376 KB
testcase_11 AC 10 ms
5,376 KB
testcase_12 AC 53 ms
5,376 KB
testcase_13 AC 1,807 ms
14,072 KB
testcase_14 AC 4,134 ms
24,136 KB
testcase_15 AC 4,374 ms
24,976 KB
testcase_16 AC 2,461 ms
15,228 KB
testcase_17 AC 3,073 ms
17,564 KB
testcase_18 AC 4,189 ms
23,888 KB
testcase_19 AC 5,988 ms
27,548 KB
testcase_20 AC 2,035 ms
14,684 KB
testcase_21 AC 4,328 ms
24,900 KB
testcase_22 AC 4,319 ms
24,852 KB
testcase_23 AC 5,988 ms
27,604 KB
testcase_24 AC 5,994 ms
27,608 KB
testcase_25 AC 5,998 ms
27,608 KB
testcase_26 AC 5,994 ms
27,608 KB
testcase_27 AC 5,977 ms
27,480 KB
testcase_28 AC 5,971 ms
27,448 KB
testcase_29 AC 5,980 ms
27,608 KB
testcase_30 AC 5,990 ms
27,480 KB
testcase_31 AC 5,978 ms
27,480 KB
testcase_32 AC 5,988 ms
27,480 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 5,975 ms
27,604 KB
testcase_36 TLE -
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 <bits/stdc++.h>
#include <atcoder/convolution>
using namespace std;
const long long MOD = 998244353;
long long modpow(long long a, long long b){
  long long ans = 1;
  while (b > 0){
    if (b % 2 == 1){
      ans *= a;
      ans %= MOD;
    }
    a *= a;
    a %= MOD;
    b /= 2;
  }
  return ans;
}
long long modinv(long long a){
  return modpow(a, MOD - 2);
}
vector<long long> diff(vector<long long> A){
  int N = A.size();
  vector<long long> B(N - 1);
  for (int i = 1; i < N; i++){
    B[i - 1] = A[i] * i % MOD;
  }
  return B;
}
vector<long long> polynomial_inverse(vector<long long> f){
  int N = f.size();
  vector<long long> ans(1);
  ans[0] = modinv(f[0]);
  for (int i = 1; i < N * 2; i *= 2){
    vector<long long> ans2 = ans;
    ans2.resize(i * 4);
    int N2 = min(N, i * 2);
    vector<long long> f2(i * 4, 0);
    for (int j = 0; j < N2; j++){
      f2[j] = f[j];
    }
    ans2 = atcoder::convolution(ans2, ans2);
    ans2.resize(i * 2);
    ans2 = atcoder::convolution(ans2, f2);
    ans2.resize(i * 2);
    for (int j = 0; j < i; j++){
      ans2[j] = MOD - ans2[j] + ans[j] * 2;
      ans2[j] %= MOD;
    }
    swap(ans, ans2);
  }
  ans.resize(N);
  return ans;
}
vector<long long> polynomial_quotient(vector<long long> f, vector<long long> g){
  int N = f.size(), M = g.size();
  if (N < M){
    return {0};
  }
  reverse(g.begin(), g.end());
  g.resize(N - M + 1);
  vector<long long> t = polynomial_inverse(g);
  reverse(f.begin(), f.end());
  vector<long long> q = atcoder::convolution(f, t);
  q.resize(N - M + 1);
  reverse(q.begin(), q.end());
  return q;
}
vector<long long> polynomial_remainder(vector<long long> f, vector<long long> g){
  int N = f.size();
  int M = g.size();
  if (M <= 100){
    for (int i = N - M; i >= 0; i--){
      long long q = f[i + M - 1] * modinv(g[M - 1]) % MOD;
      for (int j = 0; j < M; j++){
        f[i + j] += MOD - q * g[j] % MOD;
        f[i + j] %= MOD;
      }
      f.pop_back();
    }
    return f;
  } else {
    vector<long long> q = polynomial_quotient(f, g);
    vector<long long> b = atcoder::convolution(g, q);
    for (int i = 0; i < N; i++){
      f[i] += MOD - b[i];
      f[i] %= MOD;
    }
    f.resize(M - 1);
    return f;
  }
}
vector<long long> multipoint_evaluation(vector<long long> f, vector<long long> x){
  int M = x.size();
  vector<vector<long long>> g(M * 2 - 1, {1});
  for (int i = 0; i < M; i++){
    g[M - 1 + i] = vector<long long>{MOD - x[i], 1};
  }
  for (int i = M - 2; i >= 0; i--){
    g[i] = atcoder::convolution(g[i * 2 + 1], g[i * 2 + 2]);
  }
  g[0] = polynomial_remainder(f, g[0]);
  for (int i = 1; i < M * 2 - 1; i++){
    g[i] = polynomial_remainder(g[(i - 1) / 2], g[i]);
  }
  vector<long long> ans(M);
  for (int i = 0; i < M; i++){
    ans[i] = g[M - 1 + i][0];
  }
  return ans;
}
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  long long ans = 1;
  auto dfs = [&](auto dfs, int L, int R) -> vector<long long> {
    if (R - L == 1){
      return vector<long long>{MOD - A[L], 1};
    }
    int m = (L + R) / 2;
    vector<long long> fL = dfs(dfs, L, m);
    vector<long long> fR = dfs(dfs, m, R);
    vector<long long> x(R - m);
    for (int i = 0; i < R - m; i++){
      x[i] = A[m + i];
    }
    vector<long long> y = multipoint_evaluation(fL, x);
    for (int i = 0; i < R - m; i++){
      ans *= y[i];
      ans %= MOD;
    }
    vector<long long> f = atcoder::convolution(fL, fR);
    return f;
  };
  dfs(dfs, 0, N);
  if ((long long) N * (N - 1) / 2 % 2 == 1){
    ans = (MOD - ans) % MOD;
  }
  cout << ans << endl;
}
0