結果

問題 No.1668 Grayscale
ユーザー 👑 tamatotamato
提出日時 2021-09-03 22:38:35
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,210 ms / 4,000 ms
コード長 874 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 217,740 KB
最終ジャッジ日時 2023-08-21 23:32:44
合計ジャッジ時間 6,718 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,624 KB
testcase_01 AC 71 ms
71,312 KB
testcase_02 AC 71 ms
71,464 KB
testcase_03 AC 71 ms
71,616 KB
testcase_04 AC 69 ms
71,588 KB
testcase_05 AC 69 ms
71,464 KB
testcase_06 AC 516 ms
217,700 KB
testcase_07 AC 520 ms
217,740 KB
testcase_08 AC 212 ms
147,864 KB
testcase_09 AC 1,210 ms
214,196 KB
testcase_10 AC 614 ms
129,552 KB
testcase_11 AC 79 ms
75,972 KB
testcase_12 AC 89 ms
76,980 KB
testcase_13 AC 127 ms
85,816 KB
testcase_14 AC 220 ms
102,500 KB
testcase_15 AC 170 ms
87,952 KB
testcase_16 AC 145 ms
83,540 KB
testcase_17 AC 117 ms
82,592 KB
testcase_18 AC 72 ms
71,268 KB
testcase_19 AC 71 ms
71,524 KB
testcase_20 AC 85 ms
76,804 KB
testcase_21 AC 93 ms
76,512 KB
testcase_22 AC 71 ms
71,436 KB
testcase_23 AC 71 ms
71,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    d = [(0, 1), (0, -1), (-1, 0), (1, 0)]

    H, W, N = map(int, input().split())
    C = []
    for _ in range(H):
        C.append(list(map(int, input().split())))

    P = [[] for _ in range(N+1)]
    for h in range(H):
        for w in range(W):
            P[C[h][w]].append((h, w))

    ans = 1
    prev = 1
    for c in range(2, N+1):
        flg = 0
        for h, w in P[c]:
            for dh, dw in d:
                h_new, w_new = h + dh, w + dw
                if 0 <= h_new < H and 0 <= w_new < W:
                    if C[h_new][w_new] == prev:
                        flg = 1
        if flg:
            ans += 1
            prev = c
        else:
            for h, w in P[c]:
                C[h][w] = prev
    print(ans)


if __name__ == '__main__':
    main()
0