結果
| 問題 |
No.1938 Lagrange Sum
|
| コンテスト | |
| ユーザー |
👑 tatyam
|
| 提出日時 | 2022-04-09 03:37:26 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,858 ms / 3,000 ms |
| コード長 | 1,479 bytes |
| コンパイル時間 | 3,497 ms |
| コンパイル使用メモリ | 258,352 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-22 00:03:07 |
| 合計ジャッジ時間 | 23,539 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
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;
}
tatyam