Contest Duration: - (local time) (300 minutes)

Submission #7963341

Source Code Expand

Copy
```import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 998244353

"""
・(xyz+1/(xyz)+x+1/x+y+1/y+z+1/z) = (1/xyz)(xy+1)(yz+1)(xz+1) これのn乗して、mod m で(p,q,r)の係数
・xyの係数をkとすると、xz,yzの係数 mod k が決まる
・(T+1)^nをmod mでまとめておけばよい
"""

N,M,P,Q,R = map(int,read().split())

def cumprod(arr,MOD):
L = len(arr); Lsq = int(L**.5+1)
arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
for n in range(1,Lsq):
arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
for n in range(1,Lsq):
arr[n] *= arr[n-1,-1]; arr[n] %= MOD
return arr.ravel()[:L]

def make_fact(U,MOD):
x = np.arange(U,dtype=np.int64); x[0] = 1
fact = cumprod(x,MOD)
x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
fact_inv = cumprod(x,MOD)[::-1]
return fact,fact_inv

U = N+100
fact,fact_inv = make_fact(U,MOD)
# (1+T)^N
F = fact[N] * fact_inv[:N+1] % MOD * fact_inv[N::-1] % MOD

# i+j = n+r, i+k = n+q, j+k = n+p mod M
# 2i = (n+r)+(n+q)-(n+p) = n+q+r-p mod M

x = (N+Q+R-P) % M
if M&1:
if x&1: x += M
I = [x//2]
else:
if x&1:
I = []
else:
I = [x//2,(x+M)//2]

answer = 0
for i in I:
j = (N+R-i)%M
k = (N+Q-i)%M
a = F[i::M].sum() % MOD
b = F[j::M].sum() % MOD
c = F[k::M].sum() % MOD
answer += a * b % MOD * c % MOD
answer %= MOD
print(answer)
```

Submission Info

Submission Time 2019-10-13 21:56:51+0900 K - One or All maspy Python (3.4.3) 500 1539 Byte AC 290 ms 59332 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
 AC × 3
 AC × 87
Set Name Test Cases
Sample sample_00, sample_01, sample_02
All sample_00, sample_01, sample_02, testcase_0, testcase_1, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18, testcase_19, testcase_2, testcase_20, testcase_21, testcase_22, testcase_23, testcase_24, testcase_25, testcase_26, testcase_27, testcase_28, testcase_29, testcase_3, testcase_30, testcase_31, testcase_32, testcase_33, testcase_34, testcase_35, testcase_36, testcase_37, testcase_38, testcase_39, testcase_4, testcase_40, testcase_41, testcase_42, testcase_43, testcase_44, testcase_45, testcase_46, testcase_47, testcase_48, testcase_49, testcase_5, testcase_50, testcase_51, testcase_52, testcase_53, testcase_54, testcase_55, testcase_56, testcase_57, testcase_58, testcase_59, testcase_6, testcase_60, testcase_61, testcase_62, testcase_63, testcase_64, testcase_65, testcase_66, testcase_67, testcase_68, testcase_69, testcase_7, testcase_70, testcase_71, testcase_72, testcase_73, testcase_74, testcase_75, testcase_76, testcase_77, testcase_78, testcase_79, testcase_8, testcase_80, testcase_81, testcase_82, testcase_83, testcase_9
Case Name Status Exec Time Memory
sample_00 AC 152 ms 12432 KB
sample_01 AC 150 ms 12516 KB
sample_02 AC 290 ms 59332 KB
testcase_0 AC 289 ms 59332 KB
testcase_1 AC 287 ms 59332 KB
testcase_10 AC 288 ms 59332 KB
testcase_11 AC 283 ms 59332 KB
testcase_12 AC 288 ms 59332 KB
testcase_13 AC 285 ms 59332 KB
testcase_14 AC 284 ms 59332 KB
testcase_15 AC 286 ms 59332 KB
testcase_16 AC 286 ms 59332 KB
testcase_17 AC 287 ms 59204 KB
testcase_18 AC 282 ms 59332 KB
testcase_19 AC 286 ms 59332 KB
testcase_2 AC 288 ms 59332 KB
testcase_20 AC 284 ms 59332 KB
testcase_21 AC 285 ms 59332 KB
testcase_22 AC 285 ms 59332 KB
testcase_23 AC 283 ms 59332 KB
testcase_24 AC 284 ms 59332 KB
testcase_25 AC 285 ms 59332 KB
testcase_26 AC 287 ms 59332 KB
testcase_27 AC 285 ms 59120 KB
testcase_28 AC 286 ms 59332 KB
testcase_29 AC 288 ms 59332 KB
testcase_3 AC 289 ms 59332 KB
testcase_30 AC 286 ms 59332 KB
testcase_31 AC 287 ms 59332 KB
testcase_32 AC 289 ms 59332 KB
testcase_33 AC 286 ms 59248 KB
testcase_34 AC 203 ms 25368 KB
testcase_35 AC 166 ms 15636 KB
testcase_36 AC 170 ms 16708 KB
testcase_37 AC 259 ms 50484 KB
testcase_38 AC 271 ms 54060 KB
testcase_39 AC 248 ms 44724 KB
testcase_4 AC 286 ms 59332 KB
testcase_40 AC 286 ms 55616 KB
testcase_41 AC 230 ms 39572 KB
testcase_42 AC 248 ms 44424 KB
testcase_43 AC 242 ms 43292 KB
testcase_44 AC 208 ms 28412 KB
testcase_45 AC 222 ms 34764 KB
testcase_46 AC 213 ms 31116 KB
testcase_47 AC 171 ms 17184 KB
testcase_48 AC 264 ms 51060 KB
testcase_49 AC 231 ms 38404 KB
testcase_5 AC 285 ms 59332 KB
testcase_50 AC 239 ms 41484 KB
testcase_51 AC 272 ms 54420 KB
testcase_52 AC 206 ms 28020 KB
testcase_53 AC 266 ms 52628 KB
testcase_54 AC 237 ms 41416 KB
testcase_55 AC 248 ms 44932 KB
testcase_56 AC 270 ms 53992 KB
testcase_57 AC 217 ms 32960 KB
testcase_58 AC 281 ms 57596 KB
testcase_59 AC 277 ms 56156 KB
testcase_6 AC 288 ms 59332 KB
testcase_60 AC 247 ms 45796 KB
testcase_61 AC 172 ms 17644 KB
testcase_62 AC 251 ms 46592 KB
testcase_63 AC 262 ms 50808 KB
testcase_64 AC 185 ms 21144 KB
testcase_65 AC 273 ms 53852 KB
testcase_66 AC 198 ms 25356 KB
testcase_67 AC 217 ms 33124 KB
testcase_68 AC 218 ms 33316 KB
testcase_69 AC 163 ms 14676 KB
testcase_7 AC 283 ms 59332 KB
testcase_70 AC 191 ms 23804 KB
testcase_71 AC 162 ms 14432 KB
testcase_72 AC 276 ms 56356 KB
testcase_73 AC 167 ms 16036 KB
testcase_74 AC 220 ms 34556 KB
testcase_75 AC 272 ms 53844 KB
testcase_76 AC 237 ms 41284 KB
testcase_77 AC 218 ms 33388 KB
testcase_78 AC 165 ms 15252 KB
testcase_79 AC 200 ms 25716 KB
testcase_8 AC 283 ms 59332 KB
testcase_80 AC 179 ms 19492 KB
testcase_81 AC 189 ms 22452 KB
testcase_82 AC 214 ms 32156 KB
testcase_83 AC 194 ms 24276 KB
testcase_9 AC 287 ms 59204 KB