結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
AT274_
|
| 提出日時 | 2019-10-29 18:26:07 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 238 ms / 2,000 ms |
| コード長 | 331 bytes |
| コンパイル時間 | 312 ms |
| コンパイル使用メモリ | 12,416 KB |
| 実行使用メモリ | 38,564 KB |
| 最終ジャッジ日時 | 2024-09-14 21:34:11 |
| 合計ジャッジ時間 | 3,959 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
S = input()
N = len(S)
cnt = [0] * (N + 1)
farthest = {0: 0}
ans = 0
for i, s in enumerate(S, start=1):
if s == 'A':
cnt[i] = cnt[i - 1] + 1
else:
cnt[i] = cnt[i - 1] - 1
if cnt[i] not in farthest.keys():
farthest[cnt[i]] = i
else:
ans = max(ans, i - farthest[cnt[i]])
print(ans)
AT274_