結果

問題 No.1668 Grayscale
ユーザー tamatotamato
提出日時 2021-09-03 22:37:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 799 bytes
コンパイル時間 392 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 218,060 KB
最終ジャッジ日時 2023-08-21 23:29:33
合計ジャッジ時間 6,951 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 66 ms
71,288 KB
testcase_02 AC 69 ms
71,288 KB
testcase_03 AC 70 ms
71,480 KB
testcase_04 WA -
testcase_05 AC 70 ms
71,396 KB
testcase_06 WA -
testcase_07 AC 522 ms
218,060 KB
testcase_08 AC 218 ms
148,104 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 68 ms
71,596 KB
testcase_23 AC 67 ms
71,652 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
    print(ans)


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