結果

問題 No.2111 Sum of Diff
ユーザー lilictakalilictaka
提出日時 2022-11-04 13:50:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 1,027 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 86,980 KB
実行使用メモリ 137,916 KB
最終ジャッジ日時 2023-09-25 17:05:30
合計ジャッジ時間 4,943 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,192 KB
testcase_01 AC 76 ms
71,252 KB
testcase_02 AC 186 ms
137,908 KB
testcase_03 AC 152 ms
121,376 KB
testcase_04 AC 99 ms
83,088 KB
testcase_05 AC 185 ms
137,768 KB
testcase_06 AC 187 ms
137,736 KB
testcase_07 AC 108 ms
92,148 KB
testcase_08 AC 119 ms
99,408 KB
testcase_09 AC 90 ms
77,668 KB
testcase_10 AC 95 ms
80,156 KB
testcase_11 AC 135 ms
109,188 KB
testcase_12 AC 133 ms
109,496 KB
testcase_13 AC 114 ms
96,800 KB
testcase_14 AC 154 ms
107,116 KB
testcase_15 AC 183 ms
137,272 KB
testcase_16 AC 127 ms
106,080 KB
testcase_17 AC 183 ms
137,816 KB
testcase_18 AC 113 ms
96,824 KB
testcase_19 AC 154 ms
126,200 KB
testcase_20 AC 181 ms
137,916 KB
testcase_21 AC 87 ms
76,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int,input().split()))
mod = 998244353
n = len(set(A))
ans = 0
cumJ = 0
base = 1
powmat = [0] * (2 * N)
powmat[0] = 1
for i in range(1,2*N):
    powmat[i] = powmat[i-1] * 2
    powmat[i] %=mod


for i in range(N):
    ans -=(cumJ * powmat[N-1-i])%mod * A[i]
    ans %=mod
    '''
    ans += segJ.sum(0,zipped[i]) * pow(2,N-1-i) * A[i]
    ans %=mod
    '''
    cumJ += base
    cumJ %=mod
    base *=2
    base %=mod
rev2 = pow(2,mod-2,mod)
cumI = [0] * N
cumI[0] = 1
for i in range(1,N):
    cumI[i] = cumI[i-1] * rev2
    cumI[i] %=mod
def acum(List):#累積和
    rev = [0 for _ in range(len(List))]
    for i in range(len(List)):
        if i == 0:
            rev[i] = List[i]
        else:
           rev[i] = rev[i-1] + List[i] 
        rev[i] %=mod
    return rev
cumI = acum(cumI)
for i in reversed(range(N)):
    '''

    ans -= segI.sum(zipped[i]+1,n) * pow(2,N-1+i) * A[i]
    ans %=mod
    '''
    ans += ((cumI[N-1]-cumI[i]) * powmat[N-1+i]) % mod * A[i]
    ans %=mod
print(ans)



0