Source Code Status Test Cases
    Policy: public     Reviewed: 4    
14.83 sec    6512 KB    38 lines     1052 bytes    2017-05-20 03:55
import copy
import itertools
import sys

if sys.version[0] == '2':
    range, input = xrange, raw_input

drc = [(-1, 0), (0, 1), (1, 0), (0, -1)]
C_NUM = 6

def dfs(r, c, now_c, next_c):
    tmp_board[r][c] = next_c
    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:
            dfs(nr, nc, now_c, next_c)


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)
        if ope[0] == board[0][0] or ope[-1] == C - 1 or any(ope[i] == ope[i + 1] for i in range(3)):
            continue
        tmp_board = copy.deepcopy(board)
        for color in itertools.chain(ope, (C - 1, )):
            dfs(0, 0, tmp_board[0][0], color)
        dfs(0, 0, tmp_board[0][0], -1)
        cand = sum(row.count(-1) for row in tmp_board)
        if cand > ans:
            ans = cand
    print(ans)


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

Status
Judge: 2/2 Python CPU: 14.83 sec Memory: 6512 KB Length: 1052 B 2017-05-20 03:55 2017-05-20 03:55
Results for testcases
Case # Verdict CPU Time Memory In Out Case Name
Case #1: : Accepted 13.57 sec 6448 KB
Case #2: : Accepted 14.83 sec 6512 KB
< prev | / | next >  
 
Judge Input #  ( | ) Judge Output #  ( | )


Comments
 
 Under Construction.
 
Categories
 
 
Free Tags