結果

問題 No.1941 CHECKER×CHECKER(1)
ユーザー eroge_mastereroge_master
提出日時 2022-12-24 01:34:09
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,092 bytes
コンパイル時間 12,119 ms
コンパイル使用メモリ 221,772 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 04:45:30
合計ジャッジ時間 13,099 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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