結果

問題 No.1510 Simple Integral
ユーザー SSRSSSRS
提出日時 2021-05-14 23:23:44
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 2,007 bytes
コンパイル時間 1,591 ms
使用メモリ 3,664 KB
最終ジャッジ日時 2022-11-25 22:33:29
合計ジャッジ時間 3,605 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
3,384 KB
testcase_01 AC 1 ms
3,436 KB
testcase_02 AC 1 ms
3,388 KB
testcase_03 AC 2 ms
3,488 KB
testcase_04 AC 1 ms
3,488 KB
testcase_05 AC 2 ms
3,460 KB
testcase_06 AC 5 ms
3,508 KB
testcase_07 AC 5 ms
3,500 KB
testcase_08 AC 5 ms
3,600 KB
testcase_09 AC 5 ms
3,504 KB
testcase_10 AC 5 ms
3,612 KB
testcase_11 AC 5 ms
3,584 KB
testcase_12 AC 5 ms
3,560 KB
testcase_13 AC 6 ms
3,576 KB
testcase_14 AC 6 ms
3,556 KB
testcase_15 AC 6 ms
3,580 KB
testcase_16 AC 5 ms
3,628 KB
testcase_17 AC 6 ms
3,612 KB
testcase_18 AC 6 ms
3,628 KB
testcase_19 AC 6 ms
3,660 KB
testcase_20 AC 6 ms
3,588 KB
testcase_21 AC 6 ms
3,504 KB
testcase_22 AC 6 ms
3,500 KB
testcase_23 AC 6 ms
3,504 KB
testcase_24 AC 6 ms
3,580 KB
testcase_25 AC 6 ms
3,500 KB
testcase_26 AC 6 ms
3,656 KB
testcase_27 AC 6 ms
3,560 KB
testcase_28 AC 5 ms
3,504 KB
testcase_29 AC 6 ms
3,564 KB
testcase_30 AC 6 ms
3,504 KB
testcase_31 AC 6 ms
3,500 KB
testcase_32 AC 6 ms
3,584 KB
testcase_33 AC 6 ms
3,560 KB
testcase_34 AC 6 ms
3,632 KB
testcase_35 AC 5 ms
3,504 KB
testcase_36 AC 5 ms
3,572 KB
testcase_37 AC 6 ms
3,584 KB
testcase_38 AC 6 ms
3,652 KB
testcase_39 AC 6 ms
3,656 KB
testcase_40 AC 6 ms
3,560 KB
testcase_41 AC 6 ms
3,664 KB
testcase_42 AC 6 ms
3,580 KB
testcase_43 AC 2 ms
3,540 KB
testcase_44 AC 1 ms
3,380 KB
testcase_45 AC 2 ms
3,412 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