結果
問題 | No.672 最長AB列 |
ユーザー |
![]() |
提出日時 | 2018-08-18 17:39:30 |
言語 | Go (1.23.4) |
結果 |
AC
|
実行時間 | 229 ms / 2,000 ms |
コード長 | 575 bytes |
コンパイル時間 | 10,457 ms |
コンパイル使用メモリ | 221,652 KB |
実行使用メモリ | 16,064 KB |
最終ジャッジ日時 | 2024-11-06 09:18:10 |
合計ジャッジ時間 | 13,406 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
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, ok := table[scores[l] - offset[rune(S[l])]] if ok { ans = max(ans, r - l + 1) } } fmt.Println(ans) }