結果

問題 No.672 最長AB列
ユーザー とばりとばり
提出日時 2018-08-18 17:37:00
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 556 bytes
コンパイル時間 11,804 ms
コンパイル使用メモリ 239,056 KB
実行使用メモリ 15,232 KB
最終ジャッジ日時 2024-04-24 02:32:03
合計ジャッジ時間 15,145 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 WA -
testcase_10 AC 219 ms
10,112 KB
testcase_11 AC 209 ms
10,112 KB
testcase_12 AC 212 ms
5,376 KB
testcase_13 AC 193 ms
5,376 KB
testcase_14 AC 202 ms
5,376 KB
testcase_15 AC 206 ms
5,376 KB
testcase_16 AC 192 ms
5,376 KB
testcase_17 AC 214 ms
10,112 KB
testcase_18 AC 211 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import "fmt"

const MAX_LEN = 200000

func max(a int, b int) int {
	if a >= b {
		return a
	} else {
		return b
	}
}

func main() {
	var S string
	fmt.Scan(&S)

	scores := [MAX_LEN]int{}
	offset := map[rune]int{'A': 1, 'B': -1}

	for i, c := range S {
		scores[i] += offset[c]
		if i > 0 {
			scores[i] += scores[i-1]
		}
	}

	table := map[int]int{}

	ans := 0
	for l := len(S) - 1; l >= 0; l-- {
		table[scores[l]] = max(table[scores[l]], l)

		r := table[scores[l] - offset[rune(S[l])]]

		ans = max(ans, r - l + 1)
	}

	fmt.Println(ans)
}
0