結果

問題 No.1510 Simple Integral
ユーザー SSRSSSRS
提出日時 2021-05-14 23:09:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,617 bytes
コンパイル時間 1,692 ms
コンパイル使用メモリ 172,452 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-07-25 09:39:28
合計ジャッジ時間 3,976 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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];
  }
  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 (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);
      }
    }
    for (int j = 0; j < N; 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]);
    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;
  for (int i = 0; i < N; i++){
    ans += mat[i][N] * modinv(A[i]) % MOD;
  }
  ans %= MOD;
  cout << ans << endl;
}
0