結果

問題 No.1938 Lagrange Sum
ユーザー nok0nok0
提出日時 2021-12-25 18:07:39
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,155 ms / 3,000 ms
コード長 748 bytes
コンパイル時間 2,198 ms
コンパイル使用メモリ 204,252 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 05:43:29
合計ジャッジ時間 18,354 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,155 ms
4,380 KB
testcase_01 AC 1,153 ms
4,380 KB
testcase_02 AC 1,153 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 723 ms
4,380 KB
testcase_06 AC 790 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 159 ms
4,376 KB
testcase_09 AC 49 ms
4,380 KB
testcase_10 AC 1,061 ms
4,376 KB
testcase_11 AC 176 ms
4,376 KB
testcase_12 AC 1,072 ms
4,380 KB
testcase_13 AC 1,084 ms
4,376 KB
testcase_14 AC 371 ms
4,380 KB
testcase_15 AC 30 ms
4,376 KB
testcase_16 AC 1,000 ms
4,376 KB
testcase_17 AC 351 ms
4,380 KB
testcase_18 AC 358 ms
4,380 KB
testcase_19 AC 1,030 ms
4,376 KB
testcase_20 AC 1,029 ms
4,376 KB
testcase_21 AC 14 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 11 ms
4,380 KB
testcase_24 AC 1,003 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>
using namespace std;

using mint = atcoder::modint998244353;

mint res;
int main() {
	int n, X;
	cin >> n >> X;
	vector x(n, 0), y(n, 0);
	for(int i = 0; i < n; i++) cin >> x[i] >> y[i];

	vector x_diff_mul_inv(n, mint(1));
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(i == j) continue;
			x_diff_mul_inv[i] *= x[i] - x[j];
		}
		x_diff_mul_inv[i] = 1 / x_diff_mul_inv[i];
	}

	for(int i = 0; i < n; i++) {
		mint sum = 0, mul = 1;
		for(int j = 0; j < n; j++) {
			if(j == i) continue;
			mint cur = -mint(y[j]) * x_diff_mul_inv[j];
			sum += cur;
			mul *= X - x[j];
		}
		sum += mint(n - 1) * y[i] * x_diff_mul_inv[i];
		res += sum * mul;
	}
	cout << res.val() << '\n';
}
0