結果

問題 No.1938 Lagrange Sum
ユーザー noya2noya2
提出日時 2021-08-10 18:53:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 585 ms / 3,000 ms
コード長 994 bytes
コンパイル時間 4,682 ms
コンパイル使用メモリ 263,096 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 05:42:35
合計ジャッジ時間 14,783 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 584 ms
4,376 KB
testcase_01 AC 585 ms
4,376 KB
testcase_02 AC 584 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 368 ms
4,380 KB
testcase_06 AC 402 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 82 ms
4,376 KB
testcase_09 AC 26 ms
4,376 KB
testcase_10 AC 540 ms
4,376 KB
testcase_11 AC 91 ms
4,376 KB
testcase_12 AC 545 ms
4,380 KB
testcase_13 AC 551 ms
4,376 KB
testcase_14 AC 190 ms
4,380 KB
testcase_15 AC 17 ms
4,380 KB
testcase_16 AC 507 ms
4,380 KB
testcase_17 AC 180 ms
4,380 KB
testcase_18 AC 183 ms
4,376 KB
testcase_19 AC 524 ms
4,376 KB
testcase_20 AC 522 ms
4,380 KB
testcase_21 AC 8 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 6 ms
4,380 KB
testcase_24 AC 509 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/all>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define repb(i,n) for (int i = int(n)-1; i >= 0; --i)
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;

int main(){
    int n; cin >> n;
    ll X; cin >> X;
    mint z = X;
    vector<mint> x(n);
    vector<mint> y(n);
    rep(i,n){
        ll a, b; cin >> a >> b;
        x[i] = a;
        y[i] = b;
    }
    vector<mint> lrui(n+1,1);
    vector<mint> rrui(n+1,1);
    rep(i,n) lrui[i+1] = lrui[i] * (z - x[i]);
    repb(i,n) rrui[i] = rrui[i+1] * (z - x[i]);
    vector<mint> dxs(n,1);
    rep(i,n) rep(j,n){
        if (i == j) continue;
        dxs[i] *= x[i] - x[j];
    }
    rep(i,n) dxs[i] = mint(1) / dxs[i];
    mint a = 0, b = 0, c = 0;
    rep(i,n) a += y[i] * lrui[i] * rrui[i+1] * dxs[i];
    a *= n;
    rep(i,n) b += y[i] * dxs[i];
    rep(i,n) c += lrui[i] * rrui[i+1];
    mint ans = a - b * c;
    cout << ans.val() << endl;
}
0