結果
問題 | No.38 赤青白ブロック |
ユーザー | aru aru |
提出日時 | 2020-07-14 21:42:44 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 330 ms / 5,000 ms |
コード長 | 2,063 bytes |
コンパイル時間 | 11,749 ms |
コンパイル使用メモリ | 241,132 KB |
実行使用メモリ | 6,272 KB |
最終ジャッジ日時 | 2024-04-29 15:44:53 |
合計ジャッジ時間 | 21,425 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 307 ms
6,272 KB |
testcase_01 | AC | 291 ms
6,256 KB |
testcase_02 | AC | 292 ms
6,272 KB |
testcase_03 | AC | 313 ms
6,272 KB |
testcase_04 | AC | 298 ms
6,272 KB |
testcase_05 | AC | 319 ms
6,272 KB |
testcase_06 | AC | 298 ms
6,272 KB |
testcase_07 | AC | 291 ms
6,248 KB |
testcase_08 | AC | 325 ms
6,272 KB |
testcase_09 | AC | 307 ms
6,272 KB |
testcase_10 | AC | 320 ms
6,272 KB |
testcase_11 | AC | 326 ms
6,272 KB |
testcase_12 | AC | 308 ms
6,264 KB |
testcase_13 | AC | 330 ms
6,272 KB |
testcase_14 | AC | 302 ms
6,272 KB |
testcase_15 | AC | 310 ms
6,272 KB |
testcase_16 | AC | 280 ms
6,272 KB |
testcase_17 | AC | 302 ms
6,272 KB |
testcase_18 | AC | 307 ms
6,272 KB |
testcase_19 | AC | 295 ms
6,272 KB |
testcase_20 | AC | 301 ms
6,256 KB |
testcase_21 | AC | 288 ms
6,272 KB |
testcase_22 | AC | 286 ms
6,272 KB |
testcase_23 | AC | 326 ms
6,272 KB |
testcase_24 | AC | 293 ms
6,272 KB |
testcase_25 | AC | 304 ms
6,272 KB |
testcase_26 | AC | 299 ms
6,272 KB |
ソースコード
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) }