結果

問題 No.1938 Lagrange Sum
ユーザー 👑 colognecologne
提出日時 2022-05-13 22:13:22
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,032 ms / 3,000 ms
コード長 1,520 bytes
コンパイル時間 3,659 ms
コンパイル使用メモリ 250,004 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-29 07:36:12
合計ジャッジ時間 16,846 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 719 ms
4,380 KB
testcase_01 AC 719 ms
4,376 KB
testcase_02 AC 719 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 687 ms
4,380 KB
testcase_06 AC 753 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 150 ms
4,380 KB
testcase_09 AC 46 ms
4,376 KB
testcase_10 AC 1,011 ms
4,376 KB
testcase_11 AC 167 ms
4,380 KB
testcase_12 AC 1,022 ms
4,380 KB
testcase_13 AC 1,032 ms
4,380 KB
testcase_14 AC 353 ms
4,384 KB
testcase_15 AC 27 ms
4,376 KB
testcase_16 AC 951 ms
4,376 KB
testcase_17 AC 333 ms
4,376 KB
testcase_18 AC 338 ms
4,376 KB
testcase_19 AC 980 ms
4,380 KB
testcase_20 AC 980 ms
4,380 KB
testcase_21 AC 13 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 10 ms
4,376 KB
testcase_24 AC 956 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 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 = Mint(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 *= Mint(X) - xx[k];
                            d *= Mint(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