Submission #17628948


Source Code Expand

Copy
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 998_244_353

def from_read(dtype=np.int64):
    return np.fromstring(read().decode(), dtype=dtype, sep=' ')


def from_readline(dtype=np.int64):
    return np.fromstring(readline().decode(), dtype=dtype, sep=' ')

@njit
def mpow(a, n):
    p = 1
    while n:
        if n & 1:
            p = p * a % MOD
        a = a * a % MOD
        n >>= 1
    return p


@njit
def fact_table(N):
    N += 1
    fact = np.empty(N, np.int64)
    fact[0] = 1
    for n in range(1, N):
        fact[n] = n * fact[n - 1] % MOD
    fact_inv = np.empty(N, np.int64)
    fact_inv[N - 1] = mpow(fact[N - 1], MOD - 2)
    for n in range(N - 1, 0, -1):
        fact_inv[n - 1] = fact_inv[n] * n % MOD
    inv = np.empty(N, np.int64)
    inv[0] = 0
    inv[1:] = fact[:-1] * fact_inv[1:] % MOD
    return fact, fact_inv, inv

@njit((i8[:], ), cache=True)
def main(A):

    N = len(A)
    A %= MOD
    fact, fact_inv, inv = fact_table(N + 10)
    B = (A - 1) % MOD
    S = B.sum() % MOD
    coef = fact[N - 2] % MOD
    for a in A:
        coef *= a
        coef %= MOD
    # comb(S, N-2)
    x = 1
    for i in range(1, N - 1):
        x = x * (S - i + 1) % MOD
        x = x * inv[i] % MOD
    return x * coef % MOD

A = from_read()[1:]

print(main(A))

Submission Info

Submission Time
Task F - Figures
User maspy
Language Python (3.8.2)
Score 800
Code Size 1491 Byte
Status AC
Exec Time 495 ms
Memory 114808 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 4
AC × 58
Set Name Test Cases
Sample 00-Sample-00, 00-Sample-01, 00-Sample-02, 00-Sample-03
All 00-Sample-00, 00-Sample-01, 00-Sample-02, 00-Sample-03, 01-Handmade-00, 01-Handmade-01, 01-Handmade-02, 01-Handmade-03, 01-Handmade-04, 01-Handmade-05, 01-Handmade-06, 01-Handmade-07, 01-Handmade-08, 02-Small-00, 02-Small-01, 02-Small-02, 02-Small-03, 02-Small-04, 02-Small-05, 02-Small-06, 02-Small-07, 02-Small-08, 02-Small-09, 02-Small-10, 02-Small-11, 02-Small-12, 02-Small-13, 02-Small-14, 02-Small-15, 02-Small-16, 02-Small-17, 02-Small-18, 02-Small-19, 03-Large-00, 03-Large-01, 03-Large-02, 03-Large-03, 03-Large-04, 03-Large-05, 03-Large-06, 03-Large-07, 03-Large-08, 03-Large-09, 03-Large-10, 03-Large-11, 03-Large-12, 03-Large-13, 03-Large-14, 03-Large-15, 03-Large-16, 03-Large-17, 03-Large-18, 03-Large-19, 04-Tight-00, 04-Tight-01, 04-Tight-02, 04-Tight-03, 04-Tight-04
Case Name Status Exec Time Memory
00-Sample-00 AC 495 ms 106352 KB
00-Sample-01 AC 476 ms 106764 KB
00-Sample-02 AC 475 ms 106836 KB
00-Sample-03 AC 475 ms 106052 KB
01-Handmade-00 AC 493 ms 113608 KB
01-Handmade-01 AC 475 ms 106836 KB
01-Handmade-02 AC 493 ms 114444 KB
01-Handmade-03 AC 494 ms 114808 KB
01-Handmade-04 AC 492 ms 113648 KB
01-Handmade-05 AC 479 ms 107508 KB
01-Handmade-06 AC 477 ms 106540 KB
01-Handmade-07 AC 493 ms 113848 KB
01-Handmade-08 AC 477 ms 106304 KB
02-Small-00 AC 475 ms 106788 KB
02-Small-01 AC 476 ms 106112 KB
02-Small-02 AC 477 ms 106120 KB
02-Small-03 AC 481 ms 106080 KB
02-Small-04 AC 476 ms 105904 KB
02-Small-05 AC 481 ms 106284 KB
02-Small-06 AC 475 ms 106328 KB
02-Small-07 AC 473 ms 105656 KB
02-Small-08 AC 476 ms 106052 KB
02-Small-09 AC 478 ms 106096 KB
02-Small-10 AC 480 ms 106116 KB
02-Small-11 AC 475 ms 106312 KB
02-Small-12 AC 477 ms 106316 KB
02-Small-13 AC 481 ms 106364 KB
02-Small-14 AC 479 ms 106128 KB
02-Small-15 AC 480 ms 106092 KB
02-Small-16 AC 477 ms 105544 KB
02-Small-17 AC 478 ms 106076 KB
02-Small-18 AC 477 ms 106864 KB
02-Small-19 AC 482 ms 106836 KB
03-Large-00 AC 485 ms 112280 KB
03-Large-01 AC 490 ms 113076 KB
03-Large-02 AC 493 ms 114196 KB
03-Large-03 AC 479 ms 106172 KB
03-Large-04 AC 490 ms 114156 KB
03-Large-05 AC 479 ms 108040 KB
03-Large-06 AC 479 ms 108420 KB
03-Large-07 AC 495 ms 114668 KB
03-Large-08 AC 495 ms 114644 KB
03-Large-09 AC 477 ms 106800 KB
03-Large-10 AC 484 ms 109016 KB
03-Large-11 AC 491 ms 112488 KB
03-Large-12 AC 475 ms 106760 KB
03-Large-13 AC 488 ms 110532 KB
03-Large-14 AC 492 ms 111448 KB
03-Large-15 AC 474 ms 106952 KB
03-Large-16 AC 485 ms 109640 KB
03-Large-17 AC 489 ms 111692 KB
03-Large-18 AC 493 ms 114352 KB
03-Large-19 AC 486 ms 111044 KB
04-Tight-00 AC 476 ms 105620 KB
04-Tight-01 AC 477 ms 107096 KB
04-Tight-02 AC 492 ms 114176 KB
04-Tight-03 AC 482 ms 108064 KB
04-Tight-04 AC 489 ms 110896 KB