Submission #53145345


Source Code Expand

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

using namespace std;
using namespace atcoder;
using mint = modint998244353;

vector<mint> prod(const vector<int> &a, int l, int r) {
    if (r - l == 1) return {1, a[l]};
    int m = (l + r) / 2;
    return convolution(prod(a, l, m), prod(a, m, r));
}
mint f[3 * 100010], fact[3 * 100010];
int main() {
    int n;
    cin >> n;

    mint sumA = 0, prodA = 1;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sumA += a[i];
        prodA *= a[i];
    }
    vector<mint> p = prod(a, 0, n);

    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = i * fact[i - 1];

    f[n] = prodA * fact[n];
    for (int m = n - 1; m >= 0; --m) {
        f[m] = fact[m] * p[m] + f[m + 1] / (sumA - m);
    }
    cout << f[0].val() << endl;
}

Submission Info

Submission Time
Task G - Socks 3
User Ebishu0309
Language C++ 20 (gcc 12.2)
Score 600
Code Size 881 Byte
Status AC
Exec Time 324 ms
Memory 15956 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 27
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 02_minmax_00.txt, 02_minmax_01.txt, 02_minmax_02.txt, 02_minmax_03.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 2 ms 5968 KiB
00_sample_01.txt AC 2 ms 5820 KiB
00_sample_02.txt AC 2 ms 5848 KiB
01_random_00.txt AC 145 ms 10768 KiB
01_random_01.txt AC 323 ms 15804 KiB
01_random_02.txt AC 86 ms 8352 KiB
01_random_03.txt AC 322 ms 15848 KiB
01_random_04.txt AC 309 ms 15612 KiB
01_random_05.txt AC 323 ms 15756 KiB
01_random_06.txt AC 34 ms 6548 KiB
01_random_07.txt AC 324 ms 15884 KiB
01_random_08.txt AC 191 ms 11176 KiB
01_random_09.txt AC 322 ms 15956 KiB
01_random_10.txt AC 149 ms 10744 KiB
01_random_11.txt AC 322 ms 15808 KiB
01_random_12.txt AC 158 ms 10788 KiB
01_random_13.txt AC 324 ms 15752 KiB
01_random_14.txt AC 34 ms 6488 KiB
01_random_15.txt AC 323 ms 15760 KiB
01_random_16.txt AC 87 ms 8176 KiB
01_random_17.txt AC 322 ms 15808 KiB
01_random_18.txt AC 92 ms 8360 KiB
01_random_19.txt AC 324 ms 15880 KiB
02_minmax_00.txt AC 2 ms 5844 KiB
02_minmax_01.txt AC 2 ms 5872 KiB
02_minmax_02.txt AC 309 ms 15936 KiB
02_minmax_03.txt AC 324 ms 15868 KiB