結果
| 問題 | No.3370 AB → BA |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-08 23:16:00 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 489 bytes |
| 記録 | |
| コンパイル時間 | 231 ms |
| コンパイル使用メモリ | 82,032 KB |
| 実行使用メモリ | 54,224 KB |
| 最終ジャッジ日時 | 2026-01-08 23:16:02 |
| 合計ジャッジ時間 | 1,949 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | WA * 20 |
ソースコード
MOD = 998244353
def solve(S):
pos = []
cnt = 0
for i, ch in enumerate(S):
if ch == 'A':
pos.append(i + 1 - cnt)
cnt += 1
n = len(pos)
if n == 0:
return 1
maxB = pos[-1]
dp = [0] * (maxB + 1)
dp[0] = 1
for b in pos:
ndp = [0] * (maxB + 1)
pref = 0
for x in range(b):
pref = (pref + dp[x]) % MOD
ndp[x] = pref
dp = ndp
return sum(dp[:pos[-1]]) % MOD