結果

問題 No.1938 Lagrange Sum
ユーザー tatyamtatyam
提出日時 2022-04-09 03:37:26
言語 C++23(draft)
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 1,851 ms / 3,000 ms
コード長 1,479 bytes
コンパイル時間 3,303 ms
使用メモリ 9,704 KB
最終ジャッジ日時 2023-02-21 11:58:46
合計ジャッジ時間 23,835 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 462 ms
7,596 KB
testcase_01 AC 462 ms
7,668 KB
testcase_02 AC 464 ms
9,688 KB
testcase_03 AC 1 ms
7,656 KB
testcase_04 AC 1 ms
7,612 KB
testcase_05 AC 1,152 ms
7,660 KB
testcase_06 AC 1,304 ms
7,660 KB
testcase_07 AC 3 ms
7,652 KB
testcase_08 AC 253 ms
7,568 KB
testcase_09 AC 78 ms
9,696 KB
testcase_10 AC 1,738 ms
7,612 KB
testcase_11 AC 281 ms
7,592 KB
testcase_12 AC 1,782 ms
7,668 KB
testcase_13 AC 1,851 ms
7,616 KB
testcase_14 AC 601 ms
7,680 KB
testcase_15 AC 46 ms
7,680 KB
testcase_16 AC 1,638 ms
7,600 KB
testcase_17 AC 580 ms
7,680 KB
testcase_18 AC 577 ms
9,704 KB
testcase_19 AC 1,692 ms
7,608 KB
testcase_20 AC 1,678 ms
7,592 KB
testcase_21 AC 21 ms
7,608 KB
testcase_22 AC 2 ms
7,668 KB
testcase_23 AC 16 ms
7,588 KB
testcase_24 AC 1,643 ms
7,656 KB
testcase_25 AC 1 ms
9,688 KB
testcase_26 AC 1 ms
9,680 KB
testcase_27 AC 2 ms
9,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using Modint = atcoder::modint998244353;
istream& operator>>(istream& cin, Modint& x){
    int x_;
    cin >> x_;
    x = Modint::raw(x_);
    return cin;
}


int main(){
    int N;
    Modint X;
    cin >> N >> X;
    vector<pair<Modint, Modint>> P(N);
    for(auto& [x, y] : P) cin >> x >> y;
    if(auto p = find_if(P.begin(), P.end(), [&](auto p){ return p.first == X; }); p != P.end()){
        Modint ans = p->second * (N - 1);
        P.erase(p);
        for(auto [x0, y0] : P){
            pair<Modint, Modint> a = {1, 1};
            for(auto [x, y] : P) if(x != x0){
                a.first *= X - x;
                a.second *= x0 - x;
            }
            ans += a.first / a.second * y0;
        }
        cout << ans.val() << endl;
        return 0;
    }
    Modint ans = 0;
    for(auto [x0, y0] : P){
        Modint denom = 1, numer = 0;
        vector<Modint> l;
        for(auto [x, y] : P) if(x != x0){
            denom *= x0 - x;
            l.push_back(X - x);
        }
        vector<Modint> r(l.size());
        exclusive_scan(l.rbegin(), l.rend(), r.rbegin(), Modint{1}, multiplies<>{});
        exclusive_scan(l.begin(), l.end(), l.begin(), Modint{1}, multiplies<>{});
        int i = 0;
        for(auto [x, y] : P) if(x != x0){
            numer += l[i] * r[i] * (x0 - x);
            i++;
        }
        ans += numer / denom * y0;
    }
    cout << ans.val() << endl;
}
0