結果

問題 No.179 塗り分け
ユーザー FromBooskaFromBooska
提出日時 2023-02-21 14:25:39
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 340 ms / 3,000 ms
コード長 1,685 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 87,252 KB
実行使用メモリ 78,076 KB
最終ジャッジ日時 2023-09-29 07:13:31
合計ジャッジ時間 8,421 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,184 KB
testcase_01 AC 71 ms
71,280 KB
testcase_02 AC 72 ms
71,144 KB
testcase_03 AC 73 ms
71,256 KB
testcase_04 AC 74 ms
71,336 KB
testcase_05 AC 71 ms
71,208 KB
testcase_06 AC 88 ms
76,528 KB
testcase_07 AC 75 ms
75,684 KB
testcase_08 AC 75 ms
75,776 KB
testcase_09 AC 76 ms
75,812 KB
testcase_10 AC 340 ms
78,076 KB
testcase_11 AC 309 ms
77,756 KB
testcase_12 AC 296 ms
77,660 KB
testcase_13 AC 72 ms
71,164 KB
testcase_14 AC 74 ms
71,340 KB
testcase_15 AC 74 ms
71,244 KB
testcase_16 AC 74 ms
71,160 KB
testcase_17 AC 73 ms
71,168 KB
testcase_18 AC 163 ms
77,856 KB
testcase_19 AC 165 ms
77,768 KB
testcase_20 AC 80 ms
76,240 KB
testcase_21 AC 79 ms
75,516 KB
testcase_22 AC 95 ms
76,752 KB
testcase_23 AC 133 ms
77,612 KB
testcase_24 AC 92 ms
76,420 KB
testcase_25 AC 93 ms
76,580 KB
testcase_26 AC 109 ms
76,516 KB
testcase_27 AC 132 ms
77,428 KB
testcase_28 AC 159 ms
77,524 KB
testcase_29 AC 158 ms
77,776 KB
testcase_30 AC 181 ms
77,964 KB
testcase_31 AC 181 ms
77,536 KB
testcase_32 AC 189 ms
77,584 KB
testcase_33 AC 185 ms
77,464 KB
testcase_34 AC 219 ms
77,616 KB
testcase_35 AC 209 ms
77,504 KB
testcase_36 AC 75 ms
70,932 KB
testcase_37 AC 75 ms
70,932 KB
testcase_38 AC 73 ms
70,972 KB
testcase_39 AC 72 ms
71,356 KB
testcase_40 AC 72 ms
71,256 KB
testcase_41 AC 71 ms
71,064 KB
testcase_42 AC 73 ms
71,112 KB
testcase_43 AC 80 ms
76,220 KB
testcase_44 AC 94 ms
76,576 KB
testcase_45 AC 78 ms
75,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# まず黒マスは偶数個である必要
# どの黒マスとどの黒マスをペアにするか、そのペア間の(i, j)距離
# その距離で全部の黒マスをペアリングできるか

H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(input())
    
blacks = []
count = 0
count_matrix = [[-1]*W for h in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            blacks.append((count, (i, j)))
            count_matrix[i][j] = count
            count += 1
            
black_total = count
ans = 'NO'
didj_visited = set()
if black_total%2 == 0:
    for a in range(black_total):
        for b in range(a+1, black_total):
            di = blacks[b][1][0]-blacks[a][1][0]
            dj = blacks[b][1][1]-blacks[a][1][1]
            if (di, dj) in didj_visited:
                continue
            didj_visited.add((di, dj))
            
            test = True
            visited = set()
            for c in range(black_total):
                if blacks[c][0] in visited:
                    continue
                visited.add(blacks[c][0])
                if not (0 <= blacks[c][1][0]+di < H and 0 <= blacks[c][1][1]+dj < W):
                    test = False
                    break                
                nxt_num = count_matrix[blacks[c][1][0]+di][blacks[c][1][1]+dj]
                if nxt_num in visited or nxt_num == -1:
                    test = False
                    break
                else:
                    visited.add(nxt_num)
            if test == True and len(visited) == black_total:
                ans = 'YES'
                #print(blacks[a], blacks[b], di, dj)
print(ans)

0