結果
問題 | No.672 最長AB列 |
ユーザー | とばり |
提出日時 | 2018-08-18 17:39:30 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 244 ms / 2,000 ms |
コード長 | 575 bytes |
コンパイル時間 | 11,508 ms |
コンパイル使用メモリ | 221,912 KB |
実行使用メモリ | 15,360 KB |
最終ジャッジ日時 | 2024-04-24 02:33:22 |
合計ジャッジ時間 | 14,606 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 244 ms
15,360 KB |
testcase_10 | AC | 231 ms
10,112 KB |
testcase_11 | AC | 232 ms
10,112 KB |
testcase_12 | AC | 214 ms
5,376 KB |
testcase_13 | AC | 213 ms
5,376 KB |
testcase_14 | AC | 212 ms
5,376 KB |
testcase_15 | AC | 215 ms
5,376 KB |
testcase_16 | AC | 213 ms
5,376 KB |
testcase_17 | AC | 227 ms
10,112 KB |
testcase_18 | AC | 209 ms
5,376 KB |
ソースコード
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) }