Submission #1381152


Source Code Expand

H,W = map(int, raw_input().split())
src = [raw_input() for i in range(H)]

def valid():
    if H > 1:
        for x in range(W):
            if src[0][x] == '#' and src[1][x] == '.': return False
            if src[H-1][x] == '#' and src[H-2][x] == '.': return False
    if W > 1:
        for y in range(H):
            if src[y][0] == '#' and src[y][1] == '.': return False
            if src[y][W-1] == '#' and src[y][W-2] == '.': return False
    for y in range(H):
        if src[y].find('.#.') >= 0: return False
        if src[y].find('.##.') >= 0: return False
        for x in range(W):
            if H-y >= 3 and src[y][x] == '.' and src[y+1][x] == '#' and src[y+2][x] == '.':
                return False
            if H-y >= 4 and src[y][x] == '.' and src[y+1][x] == '#' and src[y+2][x] == '#' and src[y+3][x] == '.':
                return False
    return True

def solve():
    dst = ['.'*W for i in range(H)]
    if not valid():
        print 'impossible'
        return
    print 'possible'
    dst = [[None for j in range(W)] for i in range(H)]
    for y in range(H):
        for x in range(W):
            dst[y][x] = '.'
            if src[y][x] == '.': continue
            if y > 0 and src[y-1][x] == '.': continue
            if y > 0 and x > 0 and src[y-1][x-1] == '.': continue
            if x > 0 and src[y][x-1] == '.': continue
            if y < H-1 and x > 0 and src[y+1][x-1] == '.': continue
            if y < H-1 and src[y+1][x] == '.': continue
            if y < H-1 and x < W-1 and src[y+1][x+1] == '.': continue
            if x < W-1 and src[y][x+1] == '.': continue
            if y > 0 and x < W-1 and src[y-1][x+1] == '.': continue
            dst[y][x] = '#'
    for row in dst:
        print ''.join(row)
solve()

Submission Info

Submission Time
Task D - 画像処理高橋君
User prd_xxx
Language Python (2.7.6)
Score 100
Code Size 1802 Byte
Status AC
Exec Time 19 ms
Memory 2824 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 25
Set Name Test Cases
Sample example_0.txt, example_1.txt, example_2.txt
All example_0.txt, example_1.txt, example_2.txt, handmade_0.txt, handmade_1.txt, possible_0.txt, possible_1.txt, possible_2.txt, possible_3.txt, possible_4.txt, possible_5.txt, possible_6.txt, possible_7.txt, possible_8.txt, possible_9.txt, random_0.txt, random_1.txt, random_2.txt, random_3.txt, random_4.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt
Case Name Status Exec Time Memory
example_0.txt AC 11 ms 2820 KB
example_1.txt AC 11 ms 2824 KB
example_2.txt AC 11 ms 2820 KB
handmade_0.txt AC 11 ms 2824 KB
handmade_1.txt AC 11 ms 2824 KB
possible_0.txt AC 14 ms 2824 KB
possible_1.txt AC 16 ms 2824 KB
possible_2.txt AC 16 ms 2824 KB
possible_3.txt AC 17 ms 2820 KB
possible_4.txt AC 13 ms 2824 KB
possible_5.txt AC 12 ms 2824 KB
possible_6.txt AC 14 ms 2820 KB
possible_7.txt AC 19 ms 2824 KB
possible_8.txt AC 17 ms 2824 KB
possible_9.txt AC 14 ms 2824 KB
random_0.txt AC 11 ms 2824 KB
random_1.txt AC 11 ms 2824 KB
random_2.txt AC 11 ms 2824 KB
random_3.txt AC 11 ms 2824 KB
random_4.txt AC 11 ms 2820 KB
random_5.txt AC 11 ms 2820 KB
random_6.txt AC 11 ms 2824 KB
random_7.txt AC 11 ms 2824 KB
random_8.txt AC 11 ms 2820 KB
random_9.txt AC 11 ms 2824 KB