結果

問題 No.2064 Smallest Sequence on Grid
ユーザー nohakai3nohakai3
提出日時 2022-09-05 22:03:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,632 ms / 3,000 ms
コード長 488 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 82,208 KB
実行使用メモリ 120,320 KB
最終ジャッジ日時 2024-05-01 00:10:09
合計ジャッジ時間 20,551 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
51,968 KB
testcase_01 AC 37 ms
52,224 KB
testcase_02 AC 38 ms
52,224 KB
testcase_03 AC 37 ms
52,608 KB
testcase_04 AC 39 ms
52,352 KB
testcase_05 AC 39 ms
51,840 KB
testcase_06 AC 38 ms
52,096 KB
testcase_07 AC 37 ms
52,224 KB
testcase_08 AC 43 ms
52,736 KB
testcase_09 AC 39 ms
52,352 KB
testcase_10 AC 40 ms
53,120 KB
testcase_11 AC 47 ms
61,568 KB
testcase_12 AC 48 ms
60,928 KB
testcase_13 AC 53 ms
63,232 KB
testcase_14 AC 54 ms
65,536 KB
testcase_15 AC 53 ms
64,272 KB
testcase_16 AC 54 ms
65,304 KB
testcase_17 AC 130 ms
85,212 KB
testcase_18 AC 128 ms
85,224 KB
testcase_19 AC 129 ms
85,120 KB
testcase_20 AC 1,822 ms
103,168 KB
testcase_21 AC 2,006 ms
107,012 KB
testcase_22 AC 1,301 ms
95,744 KB
testcase_23 AC 1,367 ms
103,080 KB
testcase_24 AC 1,367 ms
102,656 KB
testcase_25 AC 1,374 ms
102,864 KB
testcase_26 AC 2,613 ms
119,936 KB
testcase_27 AC 2,632 ms
120,320 KB
testcase_28 AC 126 ms
84,736 KB
testcase_29 AC 2,125 ms
109,184 KB
testcase_30 AC 124 ms
84,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W=map(int,input().split())
L=list()
for i in range(H):
  s=input()
  L.append(s)
ans=list()
ans.append(L[0][0])
A=[0,0]
def f(x,y):
  if 0<=x<H and 0<=y<W:
    return True
  return False
stack=[[0,0]]
for i in range(H+W-2):
  s="z"
  S=set()
  while stack:
    a,b=stack.pop()
    for da,db in [[1,0],[0,1]]:
      if f(a+da,b+db):
        s=min(s,L[a+da][b+db])
        S.add((a+da,b+db))
  for a,b in S:
    if L[a][b]==s:
      stack.append((a,b))
  ans.append(s)
print("".join(ans))
0