結果

問題 No.2651 [Cherry 6th Tune B] $\mathbb{C}$omplex комбинат
ユーザー Today03Today03
提出日時 2024-02-23 23:13:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 999 ms / 2,500 ms
コード長 4,532 bytes
コンパイル時間 2,623 ms
コンパイル使用メモリ 213,944 KB
実行使用メモリ 40,812 KB
最終ジャッジ日時 2024-09-29 08:37:26
合計ジャッジ時間 32,528 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 914 ms
6,820 KB
testcase_03 AC 915 ms
6,820 KB
testcase_04 AC 914 ms
6,820 KB
testcase_05 AC 916 ms
15,044 KB
testcase_06 AC 922 ms
15,180 KB
testcase_07 AC 927 ms
13,440 KB
testcase_08 AC 917 ms
12,612 KB
testcase_09 AC 926 ms
13,064 KB
testcase_10 AC 928 ms
29,312 KB
testcase_11 AC 917 ms
19,032 KB
testcase_12 AC 917 ms
21,072 KB
testcase_13 AC 916 ms
24,908 KB
testcase_14 AC 910 ms
19,328 KB
testcase_15 AC 923 ms
17,740 KB
testcase_16 AC 923 ms
29,768 KB
testcase_17 AC 920 ms
19,712 KB
testcase_18 AC 921 ms
29,568 KB
testcase_19 AC 923 ms
37,100 KB
testcase_20 AC 999 ms
6,820 KB
testcase_21 AC 276 ms
14,336 KB
testcase_22 AC 486 ms
22,912 KB
testcase_23 AC 626 ms
28,672 KB
testcase_24 AC 763 ms
34,304 KB
testcase_25 AC 51 ms
6,820 KB
testcase_26 AC 447 ms
21,376 KB
testcase_27 AC 903 ms
40,204 KB
testcase_28 AC 665 ms
30,592 KB
testcase_29 AC 285 ms
14,720 KB
testcase_30 AC 63 ms
6,816 KB
testcase_31 AC 753 ms
34,176 KB
testcase_32 AC 116 ms
7,808 KB
testcase_33 AC 694 ms
31,360 KB
testcase_34 AC 419 ms
20,224 KB
testcase_35 AC 837 ms
36,992 KB
testcase_36 AC 799 ms
6,820 KB
testcase_37 AC 925 ms
40,812 KB
testcase_38 AC 918 ms
40,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef LOCAL
#include "./debug.cpp"
#else
#define debug(...)
#define print_line
#endif
using namespace std;
using ll = long long;

template <long long MOD>
struct modint {
    long long value;
    modint(long long x = 0) {
        if (x >= 0) {
            value = x % MOD;
        } else {
            value = MOD - (-x) % MOD;
        }
    }
    modint operator-() const {
        return modint(-value);
    }
    modint operator+() const {
        return modint(*this);
    }
    modint &operator+=(const modint &other) {
        value += other.value;
        if (value >= MOD) value -= MOD;
        return *this;
    }
    modint &operator-=(const modint &other) {
        value += MOD - other.value;
        if (value >= MOD) value -= MOD;
        return *this;
    }
    modint &operator*=(const modint other) {
        value = value * other.value % MOD;
        return *this;
    }
    modint &operator/=(modint other) {
        (*this) *= other.inv();
        return *this;
    }
    modint operator+(const modint &other) const {
        return modint(*this) += other;
    }
    modint operator-(const modint &other) const {
        return modint(*this) -= other;
    }
    modint operator*(const modint &other) const {
        return modint(*this) *= other;
    }
    modint operator/(const modint &other) const {
        return modint(*this) /= other;
    }
    modint pow(long long x) const {
        modint ret(1), mul(value);
        while (x) {
            if (x & 1) ret *= mul;
            mul *= mul;
            x >>= 1;
        }
        return ret;
    }
    modint inv() const {
        return pow(MOD - 2);
    }
    bool operator==(const modint &other) const {
        return value == other.value;
    }
    bool operator!=(const modint &other) const {
        return value != other.value;
    }
    friend ostream &operator<<(ostream &os, const modint &x) {
        return os << x.value;
    }
    friend istream &operator>>(istream &is, modint &x) {
        long long v;
        is >> v;
        x = modint<MOD>(v);
        return is;
    }
};
using mod998 = modint<998244353>;
using mod107 = modint<1000000007>;

using mint = mod998;

int main() {
    int T;
    cin >> T;

    while (T--) {
        int N;
        cin >> N;
        vector<mint> X(N), Y(N);
        for (int i = 0; i < N; i++) cin >> X[i] >> Y[i];

        vector<mint> A(N), B(N), C(N), D(N), E(N), F(N), G(N);
        for (int i = 0; i < N; i++) {
            A[i] = X[i] * X[i] * X[i] * X[i];
            B[i] = Y[i] * Y[i] * Y[i] * Y[i];
            C[i] = X[i] * X[i];
            D[i] = Y[i] * Y[i];
            E[i] = X[i] * Y[i];
            F[i] = E[i] * E[i];
            G[i] = (X[i] * X[i] + Y[i] * Y[i]).inv();
            A[i] *= (X[i] * X[i] + Y[i] * Y[i]).inv();
            B[i] *= (X[i] * X[i] + Y[i] * Y[i]).inv();
            C[i] *= (X[i] * X[i] + Y[i] * Y[i]).inv();
            D[i] *= (X[i] * X[i] + Y[i] * Y[i]).inv();
            E[i] *= (X[i] * X[i] + Y[i] * Y[i]).inv();
            F[i] *= (X[i] * X[i] + Y[i] * Y[i]).inv();
        }

        vector<mint> A1(N + 1), B1(N + 1), C1(N + 1), D1(N + 1), E1(N + 1), F1(N + 1), G1(N + 1);
        for (int i = 0; i < N; i++) {
            A1[i + 1] = A1[i] + A[i];
            B1[i + 1] = B1[i] + B[i];
            C1[i + 1] = C1[i] + C[i];
            D1[i + 1] = D1[i] + D[i];
            E1[i + 1] = E1[i] + E[i];
            F1[i + 1] = F1[i] + F[i];
            G1[i + 1] = G1[i] + G[i];
        }

        mint ans = 0;
        for (int i = 0; i < N; i++) {
            mint res = 0;
            res += (X[i] * X[i] * X[i] * X[i] + X[i] * X[i] * Y[i] * Y[i] * 2 + Y[i] * Y[i] * Y[i] * Y[i]) * (G1[N] - G1[i + 1]) * (X[i] * X[i] + Y[i] * Y[i]).inv();
            res -= (C1[N] - C1[i + 1]) * (X[i] * X[i] * (X[i] * X[i] + Y[i] * Y[i]).inv()) * 2;
            res += (D1[N] - D1[i + 1]) * (X[i] * X[i] * (X[i] * X[i] + Y[i] * Y[i]).inv()) * 2;
            res -= (E1[N] - E1[i + 1]) * (X[i] * Y[i] * (X[i] * X[i] + Y[i] * Y[i]).inv()) * 8;
            res += (C1[N] - C1[i + 1]) * (Y[i] * Y[i] * (X[i] * X[i] + Y[i] * Y[i]).inv()) * 2;
            res -= (D1[N] - D1[i + 1]) * (Y[i] * Y[i] * (X[i] * X[i] + Y[i] * Y[i]).inv()) * 2;
            res += (A1[N] - A1[i + 1]) * (X[i] * X[i] + Y[i] * Y[i]).inv();
            res += (B1[N] - B1[i + 1]) * (X[i] * X[i] + Y[i] * Y[i]).inv();
            res += (F1[N] - F1[i + 1]) * (X[i] * X[i] + Y[i] * Y[i]).inv() * 2;
            ans += res;
        }

        cout << ans << '\n';
    }
}
0