結果
問題 |
No.1668 Grayscale
|
ユーザー |
|
提出日時 | 2025-03-01 20:07:40 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,896 bytes |
コンパイル時間 | 301 ms |
コンパイル使用メモリ | 82,416 KB |
実行使用メモリ | 235,708 KB |
最終ジャッジ日時 | 2025-03-01 20:07:50 |
合計ジャッジ時間 | 10,191 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 7 WA * 15 |
ソースコード
## https://yukicoder.me/problems/no/1668 from collections import deque def main(): H, W, N = map(int, input().split()) C = [] for _ in range(H): C.append(list(map(int, input().split()))) queues = [[] for _ in range(N)] passed = [[-1] * W for _ in range(H)] colors = [[-1] * W for _ in range(H)] for h in range(H): for w in range(W): c = C[h][w] queues[c - 1].append((h, w)) for n in range(N): array = queues[n] for s_h, s_w in array: if passed[s_h][s_w] == -1: max_x = 0 queue = deque() queue.append((s_h, s_w)) ans_array = [(s_h, s_w)] passed[s_h][s_w] = 1 while len(queue) > 0: h, w = queue.popleft() for dh, dw in ((0, 1), (0, -1), (1, 0), (-1, 0)): new_h = dh + h new_w = dw + w if 0 <= new_h < H and 0 <= new_w < W: if C[new_h][new_w] > C[h][w]: continue elif C[new_h][new_w] < C[h][w]: max_x = max(max_x, colors[new_h][new_w]) else: if passed[new_h][new_w] == -1: passed[new_h][new_w] = 1 ans_array.append((new_h, new_w)) queue.append((new_h, new_w)) for h, w in ans_array: colors[h][w] = max_x + 1 answer = -1 for h in range(H): for w in range(W): answer = max(answer, colors[h][w]) print(answer) if __name__ == "__main__": main()