結果

問題 No.1668 Grayscale
ユーザー rlangevinrlangevin
提出日時 2023-12-05 12:10:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,300 ms / 4,000 ms
コード長 766 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 216,696 KB
最終ジャッジ日時 2023-12-05 12:10:46
合計ジャッジ時間 6,718 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 37 ms
53,460 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 492 ms
216,696 KB
testcase_07 AC 482 ms
216,568 KB
testcase_08 AC 347 ms
210,404 KB
testcase_09 AC 1,300 ms
213,884 KB
testcase_10 AC 778 ms
139,060 KB
testcase_11 AC 47 ms
62,356 KB
testcase_12 AC 61 ms
68,864 KB
testcase_13 AC 109 ms
84,192 KB
testcase_14 AC 279 ms
101,048 KB
testcase_15 AC 183 ms
86,704 KB
testcase_16 AC 144 ms
83,044 KB
testcase_17 AC 104 ms
81,360 KB
testcase_18 AC 37 ms
53,460 KB
testcase_19 AC 37 ms
53,460 KB
testcase_20 AC 57 ms
66,668 KB
testcase_21 AC 74 ms
73,040 KB
testcase_22 AC 38 ms
53,460 KB
testcase_23 AC 38 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

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