結果

問題 No.672 最長AB列
ユーザー tsuchinagatsuchinaga
提出日時 2019-03-06 09:33:30
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 525 bytes
コンパイル時間 12,275 ms
コンパイル使用メモリ 216,068 KB
実行使用メモリ 13,600 KB
最終ジャッジ日時 2023-09-05 19:04:16
合計ジャッジ時間 11,931 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 39 ms
13,600 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 8 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 8 ms
4,380 KB
testcase_16 AC 8 ms
4,380 KB
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	maxSize := 2 * int(math.Pow10(5))
	rdr := bufio.NewReaderSize(os.Stdin, maxSize)
	buf := make([]byte, 0, maxSize)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	s := string(buf)

	n := 0
	m := map[int]int{-1: 0}
	max := 0
	for i := 0; i < len(s); i++ {
		if string(s[i]) == "A" {
			n++
		} else {
			n--
		}
		if v, ok := m[n]; !ok {
			m[n] = i
		} else if max < i-v {
			max = i - v
		}
	}
	fmt.Println(max)
}
0