結果

問題 No.1668 Grayscale
ユーザー とりゐとりゐ
提出日時 2022-11-20 00:35:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,483 ms / 4,000 ms
コード長 569 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 81,612 KB
実行使用メモリ 371,548 KB
最終ジャッジ日時 2023-10-21 03:58:13
合計ジャッジ時間 9,737 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 38 ms
53,460 KB
testcase_02 AC 33 ms
53,460 KB
testcase_03 AC 32 ms
53,460 KB
testcase_04 AC 35 ms
53,460 KB
testcase_05 AC 34 ms
53,460 KB
testcase_06 AC 904 ms
371,548 KB
testcase_07 AC 917 ms
371,476 KB
testcase_08 AC 183 ms
84,868 KB
testcase_09 AC 1,483 ms
318,424 KB
testcase_10 AC 806 ms
223,388 KB
testcase_11 AC 48 ms
63,960 KB
testcase_12 AC 66 ms
70,592 KB
testcase_13 AC 126 ms
90,916 KB
testcase_14 AC 259 ms
113,836 KB
testcase_15 AC 177 ms
93,316 KB
testcase_16 AC 139 ms
84,040 KB
testcase_17 AC 97 ms
78,840 KB
testcase_18 AC 36 ms
53,460 KB
testcase_19 AC 38 ms
53,460 KB
testcase_20 AC 62 ms
71,140 KB
testcase_21 AC 64 ms
70,628 KB
testcase_22 AC 36 ms
53,460 KB
testcase_23 AC 37 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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