結果

問題 No.2513 Power Eraser
ユーザー SSRSSSRS
提出日時 2023-10-20 22:20:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5,219 ms / 6,000 ms
コード長 3,846 bytes
コンパイル時間 3,891 ms
コンパイル使用メモリ 251,956 KB
実行使用メモリ 34,804 KB
最終ジャッジ日時 2024-09-20 19:51:51
合計ジャッジ時間 134,082 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
34,672 KB
testcase_01 AC 2 ms
34,668 KB
testcase_02 AC 2 ms
34,804 KB
testcase_03 AC 4 ms
34,796 KB
testcase_04 AC 42 ms
6,944 KB
testcase_05 AC 6 ms
6,944 KB
testcase_06 AC 65 ms
6,940 KB
testcase_07 AC 24 ms
6,940 KB
testcase_08 AC 53 ms
6,940 KB
testcase_09 AC 83 ms
6,940 KB
testcase_10 AC 51 ms
6,944 KB
testcase_11 AC 5 ms
6,940 KB
testcase_12 AC 37 ms
6,944 KB
testcase_13 AC 1,554 ms
14,060 KB
testcase_14 AC 3,501 ms
24,208 KB
testcase_15 AC 3,780 ms
24,964 KB
testcase_16 AC 2,098 ms
15,212 KB
testcase_17 AC 2,596 ms
17,392 KB
testcase_18 AC 3,477 ms
23,880 KB
testcase_19 AC 5,079 ms
27,404 KB
testcase_20 AC 1,726 ms
14,684 KB
testcase_21 AC 3,777 ms
24,752 KB
testcase_22 AC 3,674 ms
24,832 KB
testcase_23 AC 5,132 ms
27,464 KB
testcase_24 AC 5,141 ms
27,464 KB
testcase_25 AC 5,110 ms
27,464 KB
testcase_26 AC 5,107 ms
27,460 KB
testcase_27 AC 5,160 ms
27,460 KB
testcase_28 AC 5,155 ms
27,460 KB
testcase_29 AC 5,180 ms
27,424 KB
testcase_30 AC 5,174 ms
27,464 KB
testcase_31 AC 5,113 ms
27,588 KB
testcase_32 AC 5,081 ms
27,460 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 5,179 ms
27,588 KB
testcase_36 AC 5,219 ms
27,464 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 <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 N = f.size();
  int M = x.size();
  if (N <= 300 && M <= 300){
    vector<long long> y(M, 0);
    for (int i = 0; i < M; i++){
      for (int j = N - 1; j >= 0; j--){
        y[i] = (y[i] * x[i] + f[j]) % MOD;
      }
    }
    return y;
  }
  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