結果

問題 No.1938 Lagrange Sum
ユーザー 👑 colognecologne
提出日時 2022-05-13 22:12:20
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,502 bytes
コンパイル時間 2,969 ms
コンパイル使用メモリ 249,648 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-29 07:33:23
合計ジャッジ時間 16,656 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 688 ms
4,376 KB
testcase_06 AC 754 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 151 ms
4,376 KB
testcase_09 AC 47 ms
4,376 KB
testcase_10 AC 1,014 ms
4,376 KB
testcase_11 AC 167 ms
4,380 KB
testcase_12 AC 1,026 ms
4,376 KB
testcase_13 AC 1,036 ms
4,380 KB
testcase_14 AC 352 ms
4,376 KB
testcase_15 AC 28 ms
4,380 KB
testcase_16 AC 954 ms
4,376 KB
testcase_17 AC 334 ms
4,380 KB
testcase_18 AC 339 ms
4,376 KB
testcase_19 AC 983 ms
4,376 KB
testcase_20 AC 980 ms
4,380 KB
testcase_21 AC 14 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 9 ms
4,376 KB
testcase_24 AC 956 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>

using namespace std;
using Mint = atcoder::modint998244353;

int main()
{
    int N, X;
    scanf("%d%d", &N, &X);
    vector<int> xx(N), yy(N);
    vector<Mint> y(N);
    for (int i = 0; i < N; i++)
        scanf("%d%d", &xx[i], &yy[i]);
    for (int i = 0; i < N; i++)
        if (xx[i] == X)
        {
            Mint ans = yy[i] * (N - 1);
            for (int j = 0; j < N; j++)
                if (j != i)
                {
                    Mint u = yy[j], d = 1;
                    for (int k = 0; k < N; k++)
                        if (k != j && k != i)
                        {
                            u *= X - xx[k];
                            d *= xx[j] - xx[k];
                        }
                    ans += u / d;
                }
            cout << ans.val() << endl;
            return 0;
        }
    for (int j = 0; j < N; j++)
    {
        Mint u = 1;
        Mint d = 1;
        for (int i = 0; i < N; i++)
            if (j != i)
            {
                u *= X - xx[i];
                d *= xx[j] - xx[i];
            }
        y[j] = Mint(yy[j]) * u / d;
    }
    vector<Mint> Xinv(N);
    for (int i = 0; i < N; i++)
        Xinv[i] = Mint(X - xx[i]).inv();

    Mint ans = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
            if (j != i)
            {
                ans += y[j] * (xx[j] - xx[i]) * Xinv[i];
            }
    }
    printf("%d\n", ans.val());
}
0