結果

問題 No.2754 Cumulate and Drop
ユーザー 👑 p-adicp-adic
提出日時 2024-05-06 19:20:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 274 ms / 2,000 ms
コード長 3,022 bytes
コンパイル時間 591 ms
コンパイル使用メモリ 82,164 KB
実行使用メモリ 128,528 KB
最終ジャッジ日時 2024-05-06 19:20:39
合計ジャッジ時間 5,887 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,736 KB
testcase_01 AC 47 ms
52,992 KB
testcase_02 AC 41 ms
52,736 KB
testcase_03 AC 43 ms
53,504 KB
testcase_04 AC 41 ms
52,992 KB
testcase_05 AC 47 ms
54,016 KB
testcase_06 AC 44 ms
53,120 KB
testcase_07 AC 41 ms
53,120 KB
testcase_08 AC 129 ms
86,580 KB
testcase_09 AC 206 ms
101,504 KB
testcase_10 AC 231 ms
103,680 KB
testcase_11 AC 201 ms
102,140 KB
testcase_12 AC 263 ms
128,076 KB
testcase_13 AC 249 ms
103,936 KB
testcase_14 AC 259 ms
128,168 KB
testcase_15 AC 205 ms
102,016 KB
testcase_16 AC 119 ms
82,176 KB
testcase_17 AC 272 ms
128,284 KB
testcase_18 AC 265 ms
128,036 KB
testcase_19 AC 274 ms
128,528 KB
権限があれば一括ダウンロードができます

ソースコード

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