結果

問題 No.672 最長AB列
ユーザー tsuchinagatsuchinaga
提出日時 2019-03-06 09:05:15
言語 Go
(1.22.1)
結果
TLE  
実行時間 -
コード長 616 bytes
コンパイル時間 12,949 ms
コンパイル使用メモリ 215,928 KB
実行使用メモリ 11,484 KB
最終ジャッジ日時 2023-09-05 19:04:00
合計ジャッジ時間 16,302 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

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

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)

	sl := len(s)
	al := strings.Count(s, "A")
	bl := sl - al
	limit := int(math.Min(float64(al), float64(bl))) * 2
	max := 0
	for i := limit; i >= 2; i -= 2 {
		for j := 0; j <= sl-i; j++ {
			if strings.Count(s[j:j+i], "A")*2 == i {
				max = i
				break
			}
		}

		if max > 0 {
			break
		}
	}
	fmt.Println(max)
}
0