結果

問題 No.179 塗り分け
ユーザー aru aruaru aru
提出日時 2020-09-04 21:43:29
言語 Go
(1.22.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,165 bytes
コンパイル時間 13,337 ms
コンパイル使用メモリ 209,728 KB
実行使用メモリ 8,240 KB
最終ジャッジ日時 2023-09-30 21:33:13
合計ジャッジ時間 15,955 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 20 ms
6,716 KB
testcase_06 AC 7 ms
5,772 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
5,584 KB
testcase_09 AC 4 ms
5,888 KB
testcase_10 AC 26 ms
6,704 KB
testcase_11 AC 23 ms
6,708 KB
testcase_12 AC 88 ms
6,704 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 53 ms
6,708 KB
testcase_19 AC 30 ms
6,704 KB
testcase_20 AC 96 ms
6,704 KB
testcase_21 AC 102 ms
6,704 KB
testcase_22 AC 100 ms
6,708 KB
testcase_23 AC 36 ms
6,708 KB
testcase_24 AC 99 ms
6,708 KB
testcase_25 AC 50 ms
6,704 KB
testcase_26 AC 70 ms
6,704 KB
testcase_27 AC 134 ms
6,700 KB
testcase_28 AC 81 ms
6,704 KB
testcase_29 AC 148 ms
7,612 KB
testcase_30 AC 109 ms
6,704 KB
testcase_31 AC 157 ms
6,704 KB
testcase_32 AC 93 ms
6,704 KB
testcase_33 AC 138 ms
6,708 KB
testcase_34 AC 97 ms
6,708 KB
testcase_35 AC 148 ms
6,708 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 WA -
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 8 ms
7,876 KB
testcase_44 AC 24 ms
8,240 KB
testcase_45 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"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
}

var H, W int
var s []string
var tot int

func match(dx, dy int) bool {
	u := make([][]int, H)
	for i := 0; i < H; i++ {
		u[i] = make([]int, W)
	}
	r, b := 0, 0
	// out("------")
	for y := 0; y < H; y++ {
		for x := 0; x < W; x++ {
			rx, ry := x, y
			bx, by := x+dx, y+dy
			if bx < 0 || bx >= W || by < 0 || by >= H {
				continue
			}
			if u[ry][rx] == 0 && s[ry][rx] == '#' {
				b++
				if s[by][bx] == '#' {
					// out("x", by, bx)
					u[by][bx] = 1
					r++
				}
			}
		}
	}
	// for y := 0; y < H; y++ {
	// 	// for x := 0; x < W; x++ {
	// 	out(u[y])
	// 	// }
	// }
	// out(r, b, tot)
	if r == b && r+b == tot {
		return true
	}
	return false
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	H, W = getInt(), getInt()
	s = make([]string, H)
	for i := 0; i < H; i++ {
		s[i] = getString()
	}
	for y := 0; y < H; y++ {
		for x := 0; x < W; x++ {
			if s[y][x] == '#' {
				tot++
			}
		}
	}
	if tot == 0 {
		out("NO")
		return
	}

	for y := -H; y < H; y++ {
		for x := -W; x < W; x++ {
			if x == 0 && y == 0 {
				continue
			}
			ret := match(x, y)
			// out(x, y, ret)
			if ret == true {
				out("YES")
				return
			}
		}
	}
	out("NO")
}
0