結果

問題 No.2754 Cumulate and Drop
ユーザー 👑 p-adicp-adic
提出日時 2024-05-06 19:20:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 3,022 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 51,128 KB
最終ジャッジ日時 2024-05-06 19:21:12
合計ジャッジ時間 19,902 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
11,264 KB
testcase_01 AC 28 ms
11,008 KB
testcase_02 AC 29 ms
11,136 KB
testcase_03 AC 31 ms
11,136 KB
testcase_04 AC 29 ms
11,008 KB
testcase_05 AC 30 ms
11,008 KB
testcase_06 AC 30 ms
11,136 KB
testcase_07 AC 30 ms
11,264 KB
testcase_08 AC 476 ms
19,312 KB
testcase_09 AC 1,396 ms
37,564 KB
testcase_10 AC 1,739 ms
44,688 KB
testcase_11 AC 1,241 ms
34,364 KB
testcase_12 TLE -
testcase_13 AC 1,895 ms
48,064 KB
testcase_14 AC 1,985 ms
50,236 KB
testcase_15 AC 1,118 ms
33,012 KB
testcase_16 AC 351 ms
17,140 KB
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

class ModB:
	B = 998244353
	length_bound = 10**6 #User definition
	length_max = min( length_bound , B )
	inverse=None
	factorial=None
	factorial_inverse=None
	def SetModulo(B):
		ModB.B = int(B)
		assert(ModB.B > 0)
		ModB.length_max = min( ModB.length_bound , ModB.B )
		ModB.inverse = [None,1 if ModB.B>1 else 0]
		ModB.factorial = [1 if ModB.B>1 else 0]
		ModB.factorial_inverse = [1 if ModB.B>1 else 0]

	def __init__(self,val,valid = False):
		self.val = int(val)
		if not valid and not(0 <= self.val < ModB.B):self.val %= ModB.B
	def ref(n):
		return n if n.__class__ == __class__ else ModB(n,True)
	def get(n):
		return n.val if n.__class__ == __class__ else n
	def copy(self):
		return ModB(self.val,True)

	def __eq__(self,x):
		return x==self.val
	def __ne__(self,other):
		return not( self == other )

	def __iadd__(self,x):
		self.val += ModB.ref(x).val
		if self.val >= ModB.B:self.val -= ModB.B
		return self
	def __add__(self,x):
		a = self.copy()
		a += x
		return a
	def __radd__(self,x):
		return ModB(x + self.val)

	def __neg__(self):
		return ModB(ModB.B - self.val if self.val else 0,True)
	def __isub__(self,x):
		self.val -= ModB.ref(x).val
		if self.val < 0:self.val += ModB.B
		return self
	def __sub__(self,x):
		a = self.copy()
		a -= x
		return a
	def __rsub__(self,x):
		return ModB(x - self.val)

	def __mul__(self,x):
		return ModB.get(x) * self
	def __rmul__(self,x):
		return ModB(self.val * x)

	def __pow__(self,n): #Supported only if n>=0.
		answer = ModB(1)
		power = self.copy()
		while n > 0:
			if n&1:answer *= power.val
			power *= power.val
			n >>= 1
		return answer
	def __xor__(self,n): #Supported only if B is a prime and val!=0, or n>=0.
		return self ** ( ( n * (2 - ModB.B) )if n < 0 else n )

	def Inverse(n): #Supported only if B is a prime.
		if n < ModB.length_max:
			while len(ModB.inverse) <= n:ModB.inverse+=[ModB.B - ModB.inverse[ModB.B % len(ModB.inverse)] * ( ModB.B // len(ModB.inverse) ) % ModB.B]
			return ModB(ModB.inverse[n],True)
		else:return ModB(n) ** ( ModB.B - 2 )
	def __truediv__(self,x):
		return ModB.Inverse(x) * self
	def __rtruediv__(self,x):
		return x * ModB(ModB.Inverse(self.val),True)

	def Factorial(n):
		while len(ModB.factorial) <= n:ModB.factorial+=[ModB.factorial[-1] * len(ModB.factorial) % ModB.B]
		return ModB(ModB.factorial[n],True)
	def FactorialInverse(n): #Supported only if B is a prime.
		while len(ModB.factorial_inverse) <= n:ModB.factorial_inverse+=[ModB.factorial_inverse[-1] * ModB.Inverse( len(ModB.factorial_inverse) ).val % ModB.B]
		return ModB(ModB.factorial_inverse[n],True)
	def Combination(n,m): #Supported only if B is a prime.
		return ModB.Factorial(n) * (ModB.FactorialInverse(m).val * ModB.FactorialInverse(n-m).val)if 0<=m<=n else ModB(0,True)
ModB.inverse = [None,1 if ModB.B>1 else 0]
ModB.factorial = [1 if ModB.B>1 else 0]
ModB.factorial_inverse = [1 if ModB.B>1 else 0]

I=input
N=int(I())
A=list(map(int,I().split()))
print((sum(A[i]*ModB.Combination(2*N-2-i,N-1)*(i+1)for i in range(N))/N).val)
0