結果

問題 No.1668 Grayscale
ユーザー rlangevin
提出日時 2023-12-05 12:10:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,303 ms / 4,000 ms
コード長 766 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 217,344 KB
最終ジャッジ日時 2024-09-27 00:12:25
合計ジャッジ時間 6,172 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

H, W, N = map(int, input().split())
G = [[] for i in range(N)]
for i in range(H):
    C = list(map(int, input().split()))
    for j in range(W):
        G[C[j] - 1].append((i, j))

temp = [[0] * W for i in range(H)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
ans = 1
que = []
for i in range(N):
    D = []
    val = 0
    for x, y in G[i]:
        for k in range(4):
            nx = x + dx[k]
            ny = y + dy[k]
            if nx < 0 or nx > H - 1 or ny < 0 or ny > W - 1:
                continue
            val |= temp[nx][ny]
        D.append((x, y))
    ans += val
    if val:
        for x, y in que:
            temp[x][y] = 0
        que = []
    for x, y in D:
        temp[x][y] = 1

    que.extend(D)

print(ans)
0