結果

問題 No.1938 Lagrange Sum
ユーザー 沙耶花沙耶花
提出日時 2022-05-13 23:15:28
言語 C++17
(gcc 12.2.0 + boost 1.81.0)
結果
AC  
実行時間 909 ms / 3,000 ms
コード長 1,298 bytes
コンパイル時間 3,753 ms
実行使用メモリ 6,328 KB
最終ジャッジ日時 2023-02-21 17:05:23
合計ジャッジ時間 16,092 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 575 ms
6,328 KB
testcase_01 AC 575 ms
6,200 KB
testcase_02 AC 575 ms
6,168 KB
testcase_03 AC 1 ms
6,180 KB
testcase_04 AC 2 ms
6,248 KB
testcase_05 AC 604 ms
6,276 KB
testcase_06 AC 664 ms
6,212 KB
testcase_07 AC 2 ms
6,272 KB
testcase_08 AC 134 ms
6,252 KB
testcase_09 AC 42 ms
6,172 KB
testcase_10 AC 890 ms
6,256 KB
testcase_11 AC 148 ms
6,284 KB
testcase_12 AC 899 ms
6,200 KB
testcase_13 AC 909 ms
6,252 KB
testcase_14 AC 312 ms
6,280 KB
testcase_15 AC 25 ms
6,268 KB
testcase_16 AC 839 ms
6,284 KB
testcase_17 AC 295 ms
6,260 KB
testcase_18 AC 300 ms
6,268 KB
testcase_19 AC 863 ms
6,196 KB
testcase_20 AC 861 ms
6,252 KB
testcase_21 AC 12 ms
6,272 KB
testcase_22 AC 1 ms
6,276 KB
testcase_23 AC 9 ms
6,204 KB
testcase_24 AC 840 ms
6,252 KB
testcase_25 AC 1 ms
6,188 KB
testcase_26 AC 1 ms
6,192 KB
testcase_27 AC 2 ms
6,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001


int main(){
	
	int N,X;
	cin>>N>>X;
	
	vector<int> x(N),y(N);
	rep(i,N)cin>>x[i]>>y[i];
	vector<mint> V(N);
	int ind = -1;
	rep(i,N){
		V[i]  =X-x[i];
		if(V[i].val()!=0)V[i] = V[i].inv();
		else ind = i;
	}
	mint ans = 0;
	if(ind == -1){
		rep(i,N){
			mint P = 1,Q = 1;
			rep(j,N){
				if(i==j)continue;
				P *= X-x[j];
				Q *= x[i]-x[j];
			}
			P /= Q;
			Q = 0;
			rep(j,N){
				if(i==j)continue;
				mint t = x[i]-x[j];//X-x[j];
				t *= V[j];///= X-x[j];
				Q += t;
			}
			P *= Q;
			P *= y[i];
			ans += P;
		}
	}
	else{
		rep(i,N){
			if(i!=ind){
				
				mint P = 1,Q = 1;
				rep(j,N){
					if(j==ind||j==i)continue;
					P *= X-x[j];
					Q *= x[i]-x[j];
				}
				P /= Q;
				P *= y[i];
				ans += P;
			}
			else{
				mint P = 1,Q = 1;
				rep(j,N){
					if(i==j)continue;
					P *= X-x[j];
					Q *= x[i]-x[j];
				}
				P /= Q;
				Q = 0;
				rep(j,N){
					if(i==j)continue;
					mint t = x[i]-x[j];//X-x[j];
					t *= V[j];///= X-x[j];
					Q += t;
				}
				P *= Q;
				P *= y[i];
				ans += P;
				
			}
		}
		
	}
	
	cout<<ans.val()<<endl;
	
    return 0;
}
0