結果
問題 |
No.1938 Lagrange Sum
|
ユーザー |
👑 ![]() |
提出日時 | 2022-04-09 03:44:06 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,874 ms / 3,000 ms |
コード長 | 1,563 bytes |
コンパイル時間 | 2,872 ms |
コンパイル使用メモリ | 259,908 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-22 00:03:44 |
合計ジャッジ時間 | 23,354 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#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; }