結果

問題 No.179 塗り分け
ユーザー buey_tbuey_t
提出日時 2023-03-24 10:03:40
言語 PyPy3
(7.3.11)
結果
AC  
実行時間 1,351 ms / 3,000 ms
コード長 2,404 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 86,952 KB
実行使用メモリ 95,916 KB
最終ジャッジ日時 2023-07-18 16:40:50
合計ジャッジ時間 33,554 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 249 ms
81,996 KB
testcase_01 AC 257 ms
82,148 KB
testcase_02 AC 263 ms
83,492 KB
testcase_03 AC 254 ms
83,004 KB
testcase_04 AC 271 ms
83,296 KB
testcase_05 AC 444 ms
85,732 KB
testcase_06 AC 315 ms
83,744 KB
testcase_07 AC 254 ms
81,892 KB
testcase_08 AC 1,245 ms
91,416 KB
testcase_09 AC 1,237 ms
94,924 KB
testcase_10 AC 768 ms
87,924 KB
testcase_11 AC 714 ms
87,328 KB
testcase_12 AC 1,139 ms
90,804 KB
testcase_13 AC 288 ms
83,320 KB
testcase_14 AC 278 ms
82,980 KB
testcase_15 AC 256 ms
82,012 KB
testcase_16 AC 256 ms
81,832 KB
testcase_17 AC 252 ms
81,808 KB
testcase_18 AC 795 ms
87,536 KB
testcase_19 AC 790 ms
87,796 KB
testcase_20 AC 1,231 ms
90,852 KB
testcase_21 AC 1,309 ms
95,916 KB
testcase_22 AC 1,351 ms
93,576 KB
testcase_23 AC 756 ms
87,580 KB
testcase_24 AC 1,276 ms
93,356 KB
testcase_25 AC 778 ms
87,716 KB
testcase_26 AC 867 ms
89,408 KB
testcase_27 AC 1,295 ms
94,968 KB
testcase_28 AC 845 ms
89,948 KB
testcase_29 AC 1,255 ms
91,528 KB
testcase_30 AC 1,059 ms
90,332 KB
testcase_31 AC 1,264 ms
92,748 KB
testcase_32 AC 899 ms
88,336 KB
testcase_33 AC 1,256 ms
91,488 KB
testcase_34 AC 887 ms
88,728 KB
testcase_35 AC 1,269 ms
91,432 KB
testcase_36 AC 248 ms
82,048 KB
testcase_37 AC 245 ms
82,120 KB
testcase_38 AC 249 ms
82,760 KB
testcase_39 AC 245 ms
82,604 KB
testcase_40 AC 248 ms
82,952 KB
testcase_41 AC 249 ms
81,900 KB
testcase_42 AC 247 ms
82,952 KB
testcase_43 AC 316 ms
83,912 KB
testcase_44 AC 422 ms
84,456 KB
testcase_45 AC 292 ms
84,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum
    from heapq import heapify, heappop, heappush
    from bisect import bisect_left, bisect_right
    from copy import deepcopy
    import copy
    import random
    from collections import deque,Counter,defaultdict
    from itertools import permutations,combinations
    from decimal import Decimal,ROUND_HALF_UP
    #tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
    from functools import lru_cache, reduce
    #@lru_cache(maxsize=None)
    from operator import add,sub,mul,xor,and_,or_,itemgetter
    INF = 10**18
    mod1 = 10**9+7
    mod2 = 998244353
    
    #DecimalならPython
    
    
    '''
    H,Wが小さい
    4重ループまでは回る
    最左上を赤で塗るとして、そこからどう平行移動するのかを全探索する
    マイナス方向が定義されてないのが問題
    '''
    
    H,W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    
    sy = -1
    sx = -1
    
    for i in range(H):
        for j in range(W):
            if S[i][j] == '#':
                sy = i
                sx = j
                break
    
    if sy == -1:
        print('NO')
        exit()
    
    for dy in range(-H,H):
        for dx in range(-W,W):
            
            if dy == dx == 0:
                continue
            
            T = deepcopy(S)
            f = True
            
            for i in range(H):
                for j in range(W):
                    if T[i][j] == '#':
                        if i+dy>=H or i+dy<0 or j+dx>=W or j+dx<0:
                            f = False
                            break
                        
                        if T[i+dy][j+dx] == '#':
                            T[i][j] = '.'
                            T[i+dy][j+dx] = '.'
                        else:
                            f = False
                            break
                
                else:
                    continue
                break
            
            if f:
                print('YES')
                exit()
    
    print('NO')
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
if __name__ == '__main__':
    main()
0