結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
tails1434
|
| 提出日時 | 2020-01-23 07:19:44 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 71 ms / 2,000 ms |
| コード長 | 397 bytes |
| コンパイル時間 | 225 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 102,272 KB |
| 最終ジャッジ日時 | 2024-07-18 10:36:15 |
| 合計ジャッジ時間 | 2,565 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
from collections import defaultdict
def main():
S = input()
cnt = 0
ans = 0
d = defaultdict(int)
d[0] = -1
for i, s in enumerate(S):
if s == 'A':
cnt += 1
else:
cnt -= 1
if cnt in d:
ans = max(ans, i - d[cnt])
else:
d[cnt] = i
print(ans)
if __name__ == "__main__":
main()
tails1434