結果

問題 No.1938 Lagrange Sum
ユーザー 沙耶花沙耶花
提出日時 2022-05-13 23:15:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 965 ms / 3,000 ms
コード長 1,298 bytes
コンパイル時間 4,284 ms
コンパイル使用メモリ 262,632 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-29 08:56:54
合計ジャッジ時間 17,374 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 649 ms
4,376 KB
testcase_01 AC 649 ms
4,380 KB
testcase_02 AC 651 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 643 ms
4,380 KB
testcase_06 AC 705 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 143 ms
4,376 KB
testcase_09 AC 45 ms
4,376 KB
testcase_10 AC 946 ms
4,376 KB
testcase_11 AC 158 ms
4,380 KB
testcase_12 AC 956 ms
4,380 KB
testcase_13 AC 965 ms
4,384 KB
testcase_14 AC 332 ms
4,376 KB
testcase_15 AC 27 ms
4,380 KB
testcase_16 AC 891 ms
4,380 KB
testcase_17 AC 313 ms
4,380 KB
testcase_18 AC 319 ms
4,380 KB
testcase_19 AC 918 ms
4,380 KB
testcase_20 AC 916 ms
4,376 KB
testcase_21 AC 13 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 9 ms
4,380 KB
testcase_24 AC 894 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 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