結果
| 問題 | No.3500 01 String |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 01:22:47 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,575 bytes |
| 記録 | |
| コンパイル時間 | 1,208 ms |
| コンパイル使用メモリ | 20,700 KB |
| 実行使用メモリ | 16,088 KB |
| 最終ジャッジ日時 | 2026-04-18 01:23:03 |
| 合計ジャッジ時間 | 3,740 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 3 WA * 17 |
ソースコード
import sys
def solve():
# 入力の読み込み
input_data = sys.stdin.read().split()
if not input_data:
return
a_str = input_data[0]
n = len(a_str)
a = [int(c) for c in a_str]
MOD = 998244353
# can_be_zero[i]: 位置 i を 0 にできるか
# (i 以前に 0 が存在するか)
can_be_zero = [False] * n
has_zero = False
for i in range(n):
if a[i] == 0:
has_zero = True
if has_zero:
can_be_zero[i] = True
# can_be_one[i]: 位置 i を 1 にできるか
# (i 以降に 1 が存在するか)
can_be_one = [False] * n
has_one = False
for i in range(n - 1, -1, -1):
if a[i] == 1:
has_one = True
if has_one:
can_be_one[i] = True
# 両方の値をとれる「自由な位置」を特定する
ans = 1
current_free_length = 0
for i in range(n):
if can_be_zero[i] and can_be_one[i]:
# 0 にも 1 にもなれる位置が連続している間、カウント
current_free_length += 1
else:
# 自由区間が途切れたら、その区間の組み合わせ数 (k+1) を掛ける
if current_free_length > 0:
ans = ans * (current_free_length + 1) % MOD
current_free_length = 0
# 最後の区間の処理
if current_free_length > 0:
ans = ans * (current_free_length + 1) % MOD
print(ans)
if __name__ == "__main__":
solve()