結果

問題 No.2064 Smallest Sequence on Grid
ユーザー とりゐとりゐ
提出日時 2022-08-27 12:01:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 811 ms / 3,000 ms
コード長 583 bytes
コンパイル時間 230 ms
コンパイル使用メモリ 82,104 KB
実行使用メモリ 170,668 KB
最終ジャッジ日時 2024-04-27 20:15:46
合計ジャッジ時間 9,715 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
55,156 KB
testcase_01 AC 33 ms
55,364 KB
testcase_02 AC 33 ms
53,868 KB
testcase_03 AC 34 ms
53,888 KB
testcase_04 AC 36 ms
54,308 KB
testcase_05 AC 34 ms
54,404 KB
testcase_06 AC 34 ms
54,180 KB
testcase_07 AC 33 ms
54,800 KB
testcase_08 AC 39 ms
60,324 KB
testcase_09 AC 37 ms
60,924 KB
testcase_10 AC 39 ms
61,988 KB
testcase_11 AC 43 ms
63,940 KB
testcase_12 AC 45 ms
64,104 KB
testcase_13 AC 47 ms
65,520 KB
testcase_14 AC 47 ms
65,460 KB
testcase_15 AC 47 ms
66,488 KB
testcase_16 AC 47 ms
67,572 KB
testcase_17 AC 233 ms
157,096 KB
testcase_18 AC 232 ms
157,144 KB
testcase_19 AC 232 ms
157,284 KB
testcase_20 AC 622 ms
164,828 KB
testcase_21 AC 686 ms
166,120 KB
testcase_22 AC 514 ms
161,448 KB
testcase_23 AC 527 ms
163,884 KB
testcase_24 AC 536 ms
164,136 KB
testcase_25 AC 540 ms
163,916 KB
testcase_26 AC 811 ms
170,484 KB
testcase_27 AC 811 ms
170,668 KB
testcase_28 AC 246 ms
157,088 KB
testcase_29 AC 707 ms
155,280 KB
testcase_30 AC 226 ms
150,192 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=[]
  ok=[0]*h
  for x,y in d:
    for dx,dy in dxdy:
      if 0<=x+dx<h and 0<=y+dy<w:
        ok[x+dx]=1
  for x in range(h):
    if ok[x]:
      todo.append((x,i+1-x))
print(*ans,sep='')
0