結果

問題 No.1668 Grayscale
コンテスト
ユーザー とりゐ
提出日時 2022-11-20 00:35:59
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 956 ms / 4,000 ms
コード長 569 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 137 ms
コンパイル使用メモリ 85,164 KB
実行使用メモリ 376,764 KB
最終ジャッジ日時 2026-04-09 12:20:59
合計ジャッジ時間 5,840 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from sys import stdin
input=lambda :stdin.readline()[:-1]

h,w,n=map(int,input().split())
c=[]
for i in range(h):
  c.append(list(map(lambda x:int(x)-1,input().split())))

frm=[set() for i in range(n)]
dxdy=[(1,0),(0,1),(-1,0),(0,-1)]
for x in range(h):
  for y in range(w):
    for dx,dy in dxdy:
      nx,ny=x+dx,y+dy
      if 0<=nx<h and 0<=ny<w:
        if c[x][y]>c[nx][ny]:
          frm[c[x][y]].add(c[nx][ny])

color=[-1]*n
tmp=1
for i in range(n):
  ng=False
  for j in frm[i]:
    if tmp==color[j]:
      ng=True
  if ng:
    tmp+=1
  color[i]=tmp

print(tmp)
0