結果

問題 No.672 最長AB列
ユーザー tsuchinagatsuchinaga
提出日時 2019-03-06 09:36:34
言語 Go
(1.22.1)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 557 bytes
コンパイル時間 11,100 ms
コンパイル使用メモリ 214,176 KB
実行使用メモリ 13,556 KB
最終ジャッジ日時 2023-09-05 19:04:30
合計ジャッジ時間 12,133 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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{0: -1}
	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(n, i, m, m[n])
	}
	fmt.Println(max)
}
0