結果
| 問題 | No.2279 OR Insertion |
| コンテスト | |
| ユーザー |
とりゐ
|
| 提出日時 | 2023-04-21 23:28:39 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 392 ms / 2,000 ms |
| コード長 | 497 bytes |
| 記録 | |
| コンパイル時間 | 444 ms |
| コンパイル使用メモリ | 81,960 KB |
| 実行使用メモリ | 77,696 KB |
| 最終ジャッジ日時 | 2024-11-06 16:50:18 |
| 合計ジャッジ時間 | 12,148 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 48 |
ソースコード
from sys import stdin
input=lambda :stdin.readline()[:-1]
n=int(input())
s=input()
mod=998244353
ans=0
pow2=[1]*(n+1)
for i in range(1,n+1):
pow2[i]=pow2[i-1]*2%mod
for i in range(n):
dp=[0]*(n+1)
dp[0]=1
cum=[0]*(n+2)
cum[1]=1
res=1
for j in range(n):
if j>=i and s[j-i]=='1':
ans+=cum[j-i+1]*pow2[max(0,n-2-j)]%mod*pow2[i]
ans%=mod
dp[j+1]=cum[j+1]-cum[j-i+1]
else:
dp[j+1]=cum[j+1]
cum[j+2]=cum[j+1]+dp[j+1]
cum[j+2]%=mod
print(ans%mod)
とりゐ