結果

問題 No.1941 CHECKER×CHECKER(1)
ユーザー Lisp_Coder
提出日時 2022-12-24 01:34:09
言語 Go
(1.23.4)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,092 bytes
コンパイル時間 9,298 ms
コンパイル使用メモリ 228,852 KB
実行使用メモリ 6,816 KB
最終ジャッジ日時 2024-11-18 05:04:27
合計ジャッジ時間 9,990 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
)

func main() {
	// マス目の情報を入力
	var s1, s2, s3 string
	fmt.Scan(&s1)
	fmt.Scan(&s2)
	fmt.Scan(&s3)

	// 市松模様の判定
	if isCheckered(s1, s2, s3) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

// isCheckeredは3つの文字列からなるマス目が市松模様であるかを判定する関数です。
func isCheckered(s1, s2, s3 string) bool {
	// 各マスの色を判定する関数を作成
	isBlack := func(r, c int) bool {
		// r行c列のマスの色を判定
		switch r {
		case 1:
			return s1[c-1:c] == "#"
		case 2:
			return s2[c-1:c] == "#"
		case 3:
			return s3[c-1:c] == "#"
		default:
			return false
		}
	}

	// 各マスを順に判定
	for r := 1; r <= 3; r++ {
		for c := 1; c <= 3; c++ {
			// 上下左右のマスの色が異なることを確認
			if (r > 1 && isBlack(r-1, c) == isBlack(r, c)) ||
				(r < 3 && isBlack(r+1, c) == isBlack(r, c)) ||
				(c > 1 && isBlack(r, c-1) == isBlack(r, c)) ||
				(c < 3 && isBlack(r, c+1) == isBlack(r, c)) {
				return false
			}
		}
	}

	return true
}
0