結果

問題 No.2064 Smallest Sequence on Grid
ユーザー とりゐとりゐ
提出日時 2022-08-27 11:38:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,481 ms / 3,000 ms
コード長 546 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 82,064 KB
実行使用メモリ 177,180 KB
最終ジャッジ日時 2024-04-27 20:17:08
合計ジャッジ時間 20,015 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,356 KB
testcase_01 AC 40 ms
54,684 KB
testcase_02 AC 40 ms
55,372 KB
testcase_03 AC 39 ms
54,932 KB
testcase_04 AC 41 ms
54,168 KB
testcase_05 AC 41 ms
54,320 KB
testcase_06 AC 41 ms
54,016 KB
testcase_07 AC 39 ms
55,000 KB
testcase_08 AC 41 ms
54,992 KB
testcase_09 AC 41 ms
54,244 KB
testcase_10 AC 43 ms
55,180 KB
testcase_11 AC 50 ms
62,884 KB
testcase_12 AC 49 ms
63,076 KB
testcase_13 AC 53 ms
64,092 KB
testcase_14 AC 54 ms
66,456 KB
testcase_15 AC 55 ms
64,348 KB
testcase_16 AC 55 ms
64,864 KB
testcase_17 AC 198 ms
156,956 KB
testcase_18 AC 201 ms
157,028 KB
testcase_19 AC 197 ms
156,864 KB
testcase_20 AC 1,787 ms
169,412 KB
testcase_21 AC 1,959 ms
170,712 KB
testcase_22 AC 1,304 ms
164,932 KB
testcase_23 AC 1,358 ms
166,980 KB
testcase_24 AC 1,347 ms
166,892 KB
testcase_25 AC 1,357 ms
167,384 KB
testcase_26 AC 2,481 ms
177,180 KB
testcase_27 AC 2,466 ms
177,160 KB
testcase_28 AC 194 ms
157,080 KB
testcase_29 AC 2,062 ms
167,708 KB
testcase_30 AC 189 ms
149,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

def f(x):
  return ord(x)-97

h,w=map(int,input().split())
s=[]
for i in range(h):
  s.append(input())
a=[[0]*w for i in range(h)]
a[0][0]=1
dxdy=[(0,1),(1,0)]
ans=[]
todo=[(0,0)]
for i in range(h+w-1):
  d=[]
  mn='z'
  for x,y in todo:
    if mn==s[x][y]:
      d.append((x,y))
    elif mn>s[x][y]:
      d=[(x,y)]
      mn=s[x][y]
  ans.append(mn)
  todo=set()
  for x,y in d:
    for dx,dy in dxdy:
      if 0<=x+dx<h and 0<=y+dy<w:
        a[x+dx][y+dy]=1
        todo.add((x+dx,y+dy))
print(*ans,sep='')
0