結果

問題 No.672 最長AB列
ユーザー 双六双六
提出日時 2020-07-25 15:27:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 532 bytes
コンパイル時間 1,111 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 110,268 KB
最終ジャッジ日時 2023-09-09 13:45:34
合計ジャッジ時間 4,206 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
73,380 KB
testcase_01 AC 107 ms
73,268 KB
testcase_02 AC 108 ms
73,028 KB
testcase_03 AC 115 ms
73,556 KB
testcase_04 AC 109 ms
73,600 KB
testcase_05 AC 109 ms
73,588 KB
testcase_06 AC 109 ms
73,592 KB
testcase_07 AC 109 ms
73,220 KB
testcase_08 AC 108 ms
73,280 KB
testcase_09 AC 146 ms
110,268 KB
testcase_10 AC 135 ms
92,940 KB
testcase_11 AC 143 ms
93,024 KB
testcase_12 AC 126 ms
78,736 KB
testcase_13 AC 122 ms
78,352 KB
testcase_14 AC 127 ms
78,512 KB
testcase_15 AC 127 ms
78,340 KB
testcase_16 AC 127 ms
78,484 KB
testcase_17 AC 136 ms
93,140 KB
testcase_18 AC 120 ms
77,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# import sys; input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

import random

#処理内容
def main():
	L = input()
	N = len(L)
	D = defaultdict(lambda:-1)
	D[0] = 0
	ans = 0
	val = 0
	for i in range(N):
		if L[i] == "A":
			val += 1
		else:
			val -= 1
		if D[val] != -1:
			ans = max(ans, i + 1 - D[val])
		else:
			D[val] = i + 1

	print(ans)


	
if __name__ == '__main__':
	main()
0