結果

問題 No.2235 Line Up Colored Balls
ユーザー jianglyjiangly
提出日時 2023-03-03 21:41:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 2,759 bytes
コンパイル時間 2,265 ms
コンパイル使用メモリ 203,824 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 04:25:27
合計ジャッジ時間 4,184 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 11 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 8 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 11 ms
4,348 KB
testcase_19 AC 11 ms
4,348 KB
testcase_20 AC 12 ms
4,348 KB
testcase_21 AC 11 ms
4,348 KB
testcase_22 AC 11 ms
4,348 KB
testcase_23 AC 11 ms
4,348 KB
testcase_24 AC 11 ms
4,348 KB
testcase_25 AC 11 ms
4,348 KB
testcase_26 AC 11 ms
4,348 KB
testcase_27 AC 11 ms
4,348 KB
testcase_28 AC 9 ms
4,348 KB
testcase_29 AC 9 ms
4,348 KB
testcase_30 AC 9 ms
4,348 KB
testcase_31 AC 9 ms
4,348 KB
testcase_32 AC 8 ms
4,348 KB
testcase_33 AC 8 ms
4,348 KB
testcase_34 AC 9 ms
4,348 KB
testcase_35 AC 9 ms
4,348 KB
testcase_36 AC 9 ms
4,348 KB
testcase_37 AC 9 ms
4,348 KB
testcase_38 AC 3 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 3 ms
4,348 KB
testcase_41 AC 7 ms
4,348 KB
testcase_42 AC 8 ms
4,348 KB
testcase_43 AC 2 ms
4,348 KB
testcase_44 AC 5 ms
4,348 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 10 ms
4,348 KB
testcase_47 AC 5 ms
4,348 KB
testcase_48 AC 11 ms
4,348 KB
testcase_49 AC 12 ms
4,348 KB
testcase_50 AC 11 ms
4,348 KB
testcase_51 AC 11 ms
4,348 KB
testcase_52 AC 11 ms
4,348 KB
testcase_53 AC 11 ms
4,348 KB
testcase_54 AC 11 ms
4,348 KB
testcase_55 AC 11 ms
4,348 KB
testcase_56 AC 11 ms
4,348 KB
testcase_57 AC 11 ms
4,348 KB
testcase_58 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using i64 = long long;
template<class T>
constexpr T power(T a, i64 b) {
    T res = 1;
    for (; b; b /= 2, a *= a) {
        if (b % 2) {
            res *= a;
        }
    }
    return res;
}

template<int P>
struct MInt {
    int x;
    constexpr MInt() : x{} {}
    constexpr MInt(i64 x) : x{norm(x % P)} {}
    
    constexpr int norm(int x) const {
        if (x < 0) {
            x += P;
        }
        if (x >= P) {
            x -= P;
        }
        return x;
    }
    constexpr int val() const {
        return x;
    }
    explicit constexpr operator int() const {
        return x;
    }
    constexpr MInt operator-() const {
        MInt res;
        res.x = norm(P - x);
        return res;
    }
    constexpr MInt inv() const {
        assert(x != 0);
        return power(*this, P - 2);
    }
    constexpr MInt &operator*=(MInt rhs) {
        x = 1LL * x * rhs.x % P;
        return *this;
    }
    constexpr MInt &operator+=(MInt rhs) {
        x = norm(x + rhs.x);
        return *this;
    }
    constexpr MInt &operator-=(MInt rhs) {
        x = norm(x - rhs.x);
        return *this;
    }
    constexpr MInt &operator/=(MInt rhs) {
        return *this *= rhs.inv();
    }
    friend constexpr MInt operator*(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res *= rhs;
        return res;
    }
    friend constexpr MInt operator+(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res += rhs;
        return res;
    }
    friend constexpr MInt operator-(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res -= rhs;
        return res;
    }
    friend constexpr MInt operator/(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res /= rhs;
        return res;
    }
    friend constexpr std::istream &operator>>(std::istream &is, MInt &a) {
        i64 v;
        is >> v;
        a = MInt(v);
        return is;
    }
    friend constexpr std::ostream &operator<<(std::ostream &os, const MInt &a) {
        return os << a.val();
    }
    friend constexpr bool operator==(MInt lhs, MInt rhs) {
        return lhs.val() == rhs.val();
    }
    friend constexpr bool operator!=(MInt lhs, MInt rhs) {
        return lhs.val() != rhs.val();
    }
};

template<int V, int P>
constexpr MInt<P> CInv = MInt<P>(V).inv();

constexpr int P = 1000000007;
using Z = MInt<P>;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N;
    std::cin >> N;
    
    std::vector<int> X(N);
    int sum = 0;
    Z ans = 0;
    for (int i = 0; i < N; i++) {
        std::cin >> X[i];
        sum += X[i];
        ans += Z(X[i]) * (X[i] - 1);
    }
    ans = Z(sum) * (sum - 1) - ans;
    ans = ans / sum + 1;
    std::cout << ans << "\n";
    
    return 0;
}
0