結果

問題 No.179 塗り分け
ユーザー seiichiseiichi
提出日時 2021-01-13 18:31:33
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 1,573 bytes
コンパイル時間 10,439 ms
コンパイル使用メモリ 210,160 KB
実行使用メモリ 8,288 KB
最終ジャッジ日時 2023-08-14 16:08:15
合計ジャッジ時間 13,670 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 7 ms
8,140 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 62 ms
8,288 KB
testcase_09 WA -
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 52 ms
8,212 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 5 ms
5,604 KB
testcase_19 AC 5 ms
5,600 KB
testcase_20 AC 58 ms
8,284 KB
testcase_21 AC 63 ms
8,284 KB
testcase_22 AC 66 ms
8,284 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 61 ms
8,284 KB
testcase_25 AC 5 ms
4,380 KB
testcase_26 WA -
testcase_27 AC 62 ms
8,276 KB
testcase_28 WA -
testcase_29 AC 62 ms
8,288 KB
testcase_30 WA -
testcase_31 AC 62 ms
8,284 KB
testcase_32 AC 21 ms
8,280 KB
testcase_33 AC 62 ms
8,276 KB
testcase_34 WA -
testcase_35 AC 62 ms
8,284 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 3 ms
5,580 KB
testcase_44 AC 8 ms
8,164 KB
testcase_45 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import "fmt"

func scan() (int, int, [][]string) {
	var H, W int
	fmt.Scan(&H, &W)
	S := make([][]string, H)
	for i := 0; i < H; i++ {
		S[i] = make([]string, W)
	}

	for i := 0; i < H; i++ {
		var s string
		fmt.Scan(&s)
		for j, c := range s {
			S[i][j] = string(c)
		}
	}
	return H, W, S
}

func check(H int, W int, dy int, dx int, S [][]string) bool {
	_S := make([][]string, len(S))
	for i := 0; i < H; i++ {
		_S[i] = make([]string, len(S[i]))
		// deep copy
		copy(_S[i], S[i])
	}

	for h := 0; h < H; h++ {
		for w := 0; w < W; w++ {
			if _S[h][w] == "#" {
				if h+dy < H && w+dx < W && _S[h+dy][w+dx] == "#" {
					_S[h][w] = "r"
					_S[h+dy][w+dx] = "b"
				} else {
					return false
				}
			}
		}
	}
	return true
}

func main() {
	H, W, S := scan()
	// H := 3
	// W := 3
	// S := [][]string{
	// 	{"#", "#", "."},
	// 	{"#", "#", "#"},
	// 	{".", "#", "."},
	// }
	// H := 5
	// W := 3
	// S := [][]string{
	// 	{".", "#", "."},
	// 	{".", "#", "."},
	// 	{".", "#", "."},
	// 	{".", "#", "."},
	// 	{".", "#", "."},
	// }
	// H := 3
	// W := 9
	// S := [][]string{
	// 	{"#", "#", "#", "#", "#", "#", ".", ".", "."},
	// 	{"#", ".", "#", "#", "#", "#", ".", "#", "."},
	// 	{"#", "#", "#", "#", "#", "#", ".", ".", "."},
	// }

	res := false
	// 先に移動量だけ決めて探索する
	for h := 0; h < H; h++ {
		for w := 0; w < W; w++ {
			if h == 0 && w == 0 {
				continue
			}
			dy, dx := h, w
			res = check(H, W, dy, dx, S)
			if res {
				goto Exit
			}
		}
	}
Exit:
	if res {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}
0