結果

問題 No.1510 Simple Integral
ユーザー SSRSSSRS
提出日時 2021-05-14 23:23:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 2,007 bytes
コンパイル時間 2,256 ms
コンパイル使用メモリ 175,000 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 03:44:59
合計ジャッジ時間 3,254 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 5 ms
6,944 KB
testcase_07 AC 5 ms
6,944 KB
testcase_08 AC 5 ms
6,944 KB
testcase_09 AC 5 ms
6,940 KB
testcase_10 AC 5 ms
6,940 KB
testcase_11 AC 5 ms
6,940 KB
testcase_12 AC 5 ms
6,944 KB
testcase_13 AC 5 ms
6,940 KB
testcase_14 AC 6 ms
6,940 KB
testcase_15 AC 5 ms
6,944 KB
testcase_16 AC 5 ms
6,944 KB
testcase_17 AC 5 ms
6,940 KB
testcase_18 AC 6 ms
6,940 KB
testcase_19 AC 6 ms
6,944 KB
testcase_20 AC 5 ms
6,944 KB
testcase_21 AC 5 ms
6,940 KB
testcase_22 AC 6 ms
6,940 KB
testcase_23 AC 5 ms
6,944 KB
testcase_24 AC 5 ms
6,944 KB
testcase_25 AC 7 ms
6,940 KB
testcase_26 AC 5 ms
6,944 KB
testcase_27 AC 5 ms
6,940 KB
testcase_28 AC 5 ms
6,940 KB
testcase_29 AC 5 ms
6,944 KB
testcase_30 AC 6 ms
6,940 KB
testcase_31 AC 6 ms
6,940 KB
testcase_32 AC 6 ms
6,940 KB
testcase_33 AC 5 ms
6,940 KB
testcase_34 AC 5 ms
6,940 KB
testcase_35 AC 5 ms
6,940 KB
testcase_36 AC 6 ms
6,940 KB
testcase_37 AC 5 ms
6,944 KB
testcase_38 AC 6 ms
6,940 KB
testcase_39 AC 6 ms
6,940 KB
testcase_40 AC 6 ms
6,940 KB
testcase_41 AC 5 ms
6,940 KB
testcase_42 AC 5 ms
6,940 KB
testcase_43 AC 1 ms
6,940 KB
testcase_44 AC 1 ms
6,940 KB
testcase_45 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
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);
}
int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  vector<vector<long long>> mat(N, vector<long long>(N + 1, 0));
  for (int i = 0; i < N; i++){
    vector<long long> f = {1};
    for (int j = 0; j < N; j++){
      if (A[i] != A[j] || j > i){
        int M = f.size();
        vector<long long> g(M + 1, 0);
        for (int k = 0; k < M; k++){
          g[k] += f[k] * A[j] % MOD * A[j];
          g[k] %= MOD;
          g[k + 1] += f[k];
          g[k + 1] %= MOD;
        }
        swap(f, g);
      }
    }
    int M = f.size();
    for (int j = 0; j < M; j++){
      mat[j][i] = f[j];
    }
  }
  mat[0][N] = 1;
  for (int i = 0; i < N; i++){
    int p = i;
    for (int j = i; j < N; j++){
      if (mat[j][i] > 0){
        p = j;
      }
    }
    swap(mat[i], mat[p]);
    assert(mat[i][i] != 0);
    long long c = modinv(mat[i][i]);
    for (int j = i + 1; j <= N; j++){
      mat[i][j] *= c;
      mat[i][j] %= MOD;
    }
    for (int j = 0; j < N; j++){
      if (i != j){
        for (int k = i + 1; k <= N; k++){
          mat[j][k] -= mat[j][i] * mat[i][k] % MOD;
          mat[j][k] += MOD;
          mat[j][k] %= MOD;
        }
      }
    }
  }
  long long ans = 0;
  int cnt = 1;
  for (int i = 0; i < N; i++){
    if (i >= 1){
      if (A[i] == A[i - 1]){
        cnt++;
      } else {
        cnt = 1;
      }
    }
    long long tmp = mat[i][N] * modinv(modpow(A[i], cnt * 2 - 1)) % MOD;
    for (int j = 1; j < cnt; j++){
      tmp *= j * 2 - 1;
      tmp %= MOD;
      tmp *= modinv(j * 2);
      tmp %= MOD;
    }
    ans += tmp;
  }
  ans %= MOD;
  cout << ans << endl;
}
0