結果

問題 No.179 塗り分け
ユーザー tsuchinagatsuchinaga
提出日時 2019-03-10 12:38:36
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 1,541 bytes
コンパイル時間 12,112 ms
コンパイル使用メモリ 209,684 KB
実行使用メモリ 5,640 KB
最終ジャッジ日時 2023-09-05 19:54:19
合計ジャッジ時間 12,952 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 13 ms
5,640 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 12 ms
5,624 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 4 ms
4,380 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 4 ms
4,376 KB
testcase_13 WA -
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 RE -
testcase_17 AC 2 ms
4,380 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 WA -
testcase_24 AC 4 ms
4,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 4 ms
4,376 KB
testcase_28 WA -
testcase_29 AC 5 ms
4,376 KB
testcase_30 WA -
testcase_31 AC 4 ms
4,376 KB
testcase_32 WA -
testcase_33 AC 4 ms
4,380 KB
testcase_34 WA -
testcase_35 AC 4 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 14 ms
5,600 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"math"
	"strconv"
	"strings"
)

func main() {
	var h, w int
	_, _ = fmt.Scan(&h, &w)

	total := 0
	line := ""
	paint := make([]int, h*w)
	black := make([]int, 0)
	for i := 0; i < h; i++ {
		_, _ = fmt.Scan(&line)
		for j, c := range line {
			if string(c) == "#" {
				total++
				paint[i*w+j] = 1
				black = append(black, i*w+j)
			}
		}
	}

	if total%2 != 0 {
		fmt.Println("NO")
		return
	}

	// 半分を塗って、塗った部分を全部同じ数だけシフトして移動可能なら成功
	start, goal := int(math.Pow(2, float64(total))), int(math.Pow(2, float64(total-1)))
	for i := start; i > goal; i-- {
		// 塗る場所の取得
		fill := fmt.Sprintf("%0"+strconv.Itoa(total)+"b", i)
		if strings.Count(fill, "1") != total/2 {
			continue
		}

		src := make([]int, 0)
		dst := make([]int, 0)
		for i, b := range fill {
			if string(b) == "1" {
				src = append(src, black[i])
			} else {
				dst = append(dst, black[i])
			}

			if len(src) < len(dst) {
				break
			}
		}
		if len(src) != len(dst) {
			continue
		}
		// fmt.Println(fill, src, dst)

		// 先頭からすべて同じ移動量で実現するかのチェック
		r := true
		s := dst[0] - src[0] // 移動量
		if s < 1 {           // 左上から右か下か右下へのシフトのみを試せばいいので、移動量が0以下はスキップ
			continue
		}

		for j := 1; j < len(src); j++ {
			if src[j]+s != dst[j] {
				r = false
				break
			}
		}
		if r {
			fmt.Println("YES")
			return
		}
	}

	fmt.Println("NO")
}
0