結果

問題 No.1938 Lagrange Sum
ユーザー 👑 tatyamtatyam
提出日時 2022-04-09 03:44:06
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,857 ms / 3,000 ms
コード長 1,563 bytes
コンパイル時間 2,820 ms
コンパイル使用メモリ 258,824 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-29 05:44:24
合計ジャッジ時間 23,390 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 460 ms
4,380 KB
testcase_01 AC 460 ms
4,376 KB
testcase_02 AC 460 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1,218 ms
4,380 KB
testcase_06 AC 1,365 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 266 ms
4,380 KB
testcase_09 AC 82 ms
4,376 KB
testcase_10 AC 1,821 ms
4,380 KB
testcase_11 AC 295 ms
4,380 KB
testcase_12 AC 1,837 ms
4,376 KB
testcase_13 AC 1,857 ms
4,380 KB
testcase_14 AC 630 ms
4,380 KB
testcase_15 AC 48 ms
4,380 KB
testcase_16 AC 1,715 ms
4,376 KB
testcase_17 AC 598 ms
4,376 KB
testcase_18 AC 607 ms
4,380 KB
testcase_19 AC 1,768 ms
4,376 KB
testcase_20 AC 1,767 ms
4,376 KB
testcase_21 AC 22 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 16 ms
4,376 KB
testcase_24 AC 1,720 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 1 ms
4,384 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;
    Modint ans = 0;
    if(any_of(P.begin(), P.end(), [&](auto p){ return p.first == X; })){
        auto p = find_if(P.begin(), P.end(), [&](auto p){ return p.first == X; });
        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;
        }
    }
    else{
        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