結果
| 問題 | No.2004 Incremental Coins |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-08 23:14:42 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 534 bytes |
| コンパイル時間 | 338 ms |
| コンパイル使用メモリ | 81,920 KB |
| 実行使用メモリ | 270,484 KB |
| 最終ジャッジ日時 | 2024-12-28 08:37:17 |
| 合計ジャッジ時間 | 34,883 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 1 WA * 8 TLE * 11 |
ソースコード
n,k=map(int,input().split())
a=list(map(int,input().split()))
p=list(map(int,input().split()))
s=a.copy()
mod=998244353
for i in range(n):s[p[i]]+=a[i+1]
t=s.copy()
for i in range(n):t[p[i]]+=s[i+1]
l=[(t[i]-s[i])-(s[i]-a[i])for i in range(n+1)]
def sum(a, r, n):
if n == 1:return a % mod
x = sum(a, r, n//2)
ret = (x + pow(r, n//2, mod) * x) % mod
if n & 1:ret = (a + r * ret) % mod
return ret
for i in range(n+1):
ans=a[i]
if l[i]!=0:ans+=sum(1,t[i]-s[i],k)
else:ans+=(t[i]-s[i])*k%mod
print(ans)