結果

問題 No.38 赤青白ブロック
ユーザー aru aruaru aru
提出日時 2020-07-14 21:42:44
言語 Go
(1.22.1)
結果
AC  
実行時間 316 ms / 5,000 ms
コード長 2,063 bytes
コンパイル時間 16,380 ms
コンパイル使用メモリ 207,484 KB
実行使用メモリ 8,212 KB
最終ジャッジ日時 2023-08-12 00:54:28
合計ジャッジ時間 26,470 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 296 ms
8,200 KB
testcase_01 AC 284 ms
8,204 KB
testcase_02 AC 279 ms
8,204 KB
testcase_03 AC 296 ms
8,200 KB
testcase_04 AC 289 ms
8,204 KB
testcase_05 AC 311 ms
8,212 KB
testcase_06 AC 289 ms
8,204 KB
testcase_07 AC 280 ms
8,204 KB
testcase_08 AC 309 ms
8,204 KB
testcase_09 AC 290 ms
8,204 KB
testcase_10 AC 307 ms
8,204 KB
testcase_11 AC 308 ms
8,204 KB
testcase_12 AC 284 ms
8,200 KB
testcase_13 AC 303 ms
8,200 KB
testcase_14 AC 284 ms
8,208 KB
testcase_15 AC 290 ms
8,208 KB
testcase_16 AC 269 ms
8,208 KB
testcase_17 AC 280 ms
8,204 KB
testcase_18 AC 286 ms
8,200 KB
testcase_19 AC 280 ms
8,200 KB
testcase_20 AC 281 ms
8,200 KB
testcase_21 AC 268 ms
8,208 KB
testcase_22 AC 271 ms
8,200 KB
testcase_23 AC 316 ms
8,204 KB
testcase_24 AC 277 ms
8,204 KB
testcase_25 AC 292 ms
8,200 KB
testcase_26 AC 281 ms
8,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"math/bits"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func check(s string, fr, fb, r, b int) bool {
	cntR := 0
	cntB := 0
	str := make([]byte, 0)

	for i := 0; i < len(s); i++ {
		if s[i] == 'W' {
			str = append(str, s[i])
		} else if s[i] == 'R' {
			if (fr>>cntR)&1 == 1 {
				str = append(str, s[i])
			}
			cntR++
		} else if s[i] == 'B' {
			if (fb>>cntB)&1 == 1 {
				str = append(str, s[i])
			}
			cntB++
		}
	}
	// fmt.Printf("%10.10b %10.10b ", fr, fb)
	// out(s, string(str))
	for i := 0; i < len(str); i++ {
		if str[i] == 'W' {
			continue
		}
		if i+r < len(str) {
			if str[i] == 'R' && str[i+r] == 'R' {
				return false
			}
		}
		if i+b < len(str) {
			if str[i] == 'B' && str[i+b] == 'B' {
				return false
			}
		}
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	Kr, Kb := getInt(), getInt()
	s := getString()
	ans := 0
	t := 1 << 10
	for r := 0; r < t; r++ {
		for b := 0; b < t; b++ {
			c := check(s, r, b, Kr, Kb)
			// out(c)
			if c == true {
				ans = max(ans,
					bits.OnesCount(uint(r))+
						bits.OnesCount(uint(b))+10)
			}
		}
	}
	out(ans)
}
0