結果

問題 No.1938 Lagrange Sum
ユーザー pockynypockyny
提出日時 2022-05-13 23:19:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 965 bytes
コンパイル時間 726 ms
コンパイル使用メモリ 73,656 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-29 09:00:56
合計ジャッジ時間 9,503 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
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 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <atcoder/modint>

using namespace std;
using namespace atcoder;
using mint = modint998244353;
mint x[10010],y[10010],z[10010],sumL[10010],sumR[10010],dif[10010];
int main(){
    int i,j,n; cin >> n;
    int a; cin >> a; mint X = a;
    for(i=0;i<n;i++){
        int b,c; cin >> b >> c; x[i] = b; y[i] = c;
    }
    for(i=0;i<n;i++){
        dif[i] = 1;
        for(j=0;j<n;j++){
            if(j==i) continue;
            dif[i] *= (x[i] - x[j]);
        }
    }
    sumL[0] = 1;
    for(i=1;i<=n;i++) sumL[i] = sumL[i - 1]*(X - x[i]);
    sumR[n] = 1;
    for(i=n - 1;i>=0;i--) sumR[i] = sumR[i + 1]*(X - x[i]);
    mint ans = 0;
    for(i=0;i<n;i++){
        ans += y[i]*sumL[i]*sumR[i + 1]/dif[i];
    }
    ans *= (mint)(n - 1);
    for(i=0;i<n;i++) z[i] = y[i]/dif[i];
    mint sum = 0;
    for(i=0;i<n;i++) sum += z[i];
    for(i=0;i<n;i++){
        ans -= (sum - z[i])*sumL[i]*sumR[i + 1];
    }
    cout << ans.val() << "\n";
}
0