Source Code Status Test Cases
    Policy: public     Reviewed: 3    
40.00 sec    8068 KB    43 lines     1376 bytes    2017-05-20 03:15
import copy
import itertools


drc = [(-1, 0), (0, 1), (1, 0), (0, -1)]
C_NUM = 6
while True:
    H, W, C = map(int, input().split())
    if not (H | W | C):
        break
    board = [[int(x) - 1 for x in input().split()] for _ in range(H)]
    ans = 0
    for ope in itertools.product(range(C_NUM), repeat=4):
        # print(ope)
        tmp_board = copy.deepcopy(board)
        for color in itertools.chain(ope, (C - 1,)):
            now_c = tmp_board[0][0]
            if now_c == color:
                continue
            stack = [(0, 0)]
            while stack:
                r, c = stack.pop()
                if tmp_board[r][c] == color:
                    continue
                tmp_board[r][c] = color
                for dr, dc in drc:
                    nr, nc = r + dr, c + dc
                    if 0 <= nr < H and 0 <= nc < W and tmp_board[nr][nc] == now_c:
                        stack.append((nr, nc))
        stack = [(0, 0)]
        while stack:
            r, c = stack.pop()
            if tmp_board[r][c] == -1:
                continue
            tmp_board[r][c] = -1
            for dr, dc in drc:
                nr, nc = r + dr, c + dc
                if 0 <= nr < H and 0 <= nc < W and tmp_board[nr][nc] == C - 1:
                    stack.append((nr, nc))
        ans = max(ans, sum(row.count(-1) for row in tmp_board))
    print(ans)


Compile Error Logs:
You are not authorized to see the message.

Status
Judge: 0/2 Python3 CPU: 40.00 sec Memory: 8068 KB Length: 1376 B 2017-05-20 03:15 2017-05-20 03:16
Results for testcases
Case # Verdict CPU Time Memory In Out Case Name
Case #1: : Runtime Error - -
Case #2: - - -
< prev | / | next >  
 
Judge Input #  ( | ) Judge Output #  ( | )


Comments
 
 Under Construction.
 
Categories
 
 
Free Tags