結果

問題 No.1938 Lagrange Sum
ユーザー nok0nok0
提出日時 2021-12-25 18:07:39
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 1,138 ms / 3,000 ms
コード長 748 bytes
コンパイル時間 1,914 ms
使用メモリ 9,772 KB
最終ジャッジ日時 2023-02-21 11:58:17
合計ジャッジ時間 18,087 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1,138 ms
9,692 KB
testcase_01 AC 1,138 ms
7,680 KB
testcase_02 AC 1,138 ms
7,616 KB
testcase_03 AC 2 ms
7,672 KB
testcase_04 AC 2 ms
7,592 KB
testcase_05 AC 714 ms
7,584 KB
testcase_06 AC 781 ms
7,576 KB
testcase_07 AC 2 ms
7,672 KB
testcase_08 AC 157 ms
7,672 KB
testcase_09 AC 49 ms
7,660 KB
testcase_10 AC 1,049 ms
7,604 KB
testcase_11 AC 173 ms
7,680 KB
testcase_12 AC 1,060 ms
7,568 KB
testcase_13 AC 1,070 ms
7,672 KB
testcase_14 AC 367 ms
7,656 KB
testcase_15 AC 29 ms
9,692 KB
testcase_16 AC 987 ms
9,692 KB
testcase_17 AC 345 ms
7,604 KB
testcase_18 AC 352 ms
7,608 KB
testcase_19 AC 1,019 ms
9,680 KB
testcase_20 AC 1,014 ms
9,696 KB
testcase_21 AC 14 ms
7,724 KB
testcase_22 AC 1 ms
7,576 KB
testcase_23 AC 10 ms
7,576 KB
testcase_24 AC 990 ms
7,684 KB
testcase_25 AC 1 ms
7,572 KB
testcase_26 AC 1 ms
9,688 KB
testcase_27 AC 1 ms
9,772 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