結果

問題 No.179 塗り分け
ユーザー RaffRaff
提出日時 2022-03-07 17:08:48
言語 Go
(1.22.1)
結果
AC  
実行時間 39 ms / 3,000 ms
コード長 1,620 bytes
コンパイル時間 11,306 ms
コンパイル使用メモリ 211,892 KB
実行使用メモリ 8,248 KB
最終ジャッジ日時 2023-09-29 18:14:03
合計ジャッジ時間 13,831 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 3 ms
5,532 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 39 ms
8,248 KB
testcase_08 AC 12 ms
8,120 KB
testcase_09 AC 17 ms
8,236 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 17 ms
6,648 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 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 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 18 ms
8,248 KB
testcase_21 AC 20 ms
8,240 KB
testcase_22 AC 27 ms
8,248 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 18 ms
8,240 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 12 ms
8,132 KB
testcase_27 AC 17 ms
8,236 KB
testcase_28 AC 11 ms
8,128 KB
testcase_29 AC 17 ms
8,244 KB
testcase_30 AC 13 ms
8,188 KB
testcase_31 AC 20 ms
8,244 KB
testcase_32 AC 3 ms
4,432 KB
testcase_33 AC 18 ms
8,240 KB
testcase_34 AC 12 ms
8,128 KB
testcase_35 AC 18 ms
8,244 KB
testcase_36 AC 1 ms
4,384 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 1 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 4 ms
4,480 KB
testcase_45 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func print(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

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

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

func nextFloat() float64 {
	sc.Scan()
	i, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func chmax(a *int, b int) {
	if *a < b {
		*a = b
	}
}

func chmin(a *int, b int) {
	if *a > b {
		*a = b
	}
}

func reverse(s string) string {
	rs := []rune(s)
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		rs[i], rs[j] = rs[j], rs[i]
	}
	return string(rs)
}

var (
	H, W int
	S    []string
)

func solve(dy, dx int) bool {
	used := make([][]bool, H)
	for i := range used {
		used[i] = make([]bool, W)
	}
	ok := false
	for i := range S {
		for j := range S[i] {
			if S[i][j] == '#' && !used[i][j] {
				if i+dy >= H || j+dx >= W {
					return false
				}
				if S[i+dy][j+dx] == '#' && !used[i+dy][j+dx] {
					used[i+dy][j+dx] = true
				} else {
					return false
				}
				ok = true
			}
		}
	}
	return ok
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)

	H, W = nextInt(), nextInt()

	S = make([]string, H)
	for i := range S {
		S[i] = nextString()
	}
	for i := 0; i < 2; i++ {
		for i := range S {
			for j := range S[i] {
				if i == 0 && j == 0 {
					continue
				}
				if solve(i, j) {
					print("YES")
					return
				}
			}
		}
		for i := range S {
			S[i] = reverse(S[i])
		}
	}
	print("NO")
}
0