結果

問題 No.2064 Smallest Sequence on Grid
ユーザー flygonflygon
提出日時 2022-09-18 23:27:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,895 ms / 3,000 ms
コード長 658 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 82,388 KB
実行使用メモリ 106,292 KB
最終ジャッジ日時 2024-06-01 15:50:58
合計ジャッジ時間 16,345 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,536 KB
testcase_01 AC 39 ms
52,628 KB
testcase_02 AC 39 ms
52,568 KB
testcase_03 AC 40 ms
52,496 KB
testcase_04 AC 39 ms
53,344 KB
testcase_05 AC 39 ms
52,788 KB
testcase_06 AC 39 ms
52,572 KB
testcase_07 AC 40 ms
52,156 KB
testcase_08 AC 41 ms
52,536 KB
testcase_09 AC 40 ms
53,500 KB
testcase_10 AC 40 ms
53,424 KB
testcase_11 AC 42 ms
53,544 KB
testcase_12 AC 43 ms
53,500 KB
testcase_13 AC 51 ms
62,908 KB
testcase_14 AC 54 ms
64,156 KB
testcase_15 AC 53 ms
64,900 KB
testcase_16 AC 53 ms
64,724 KB
testcase_17 AC 132 ms
85,564 KB
testcase_18 AC 131 ms
85,700 KB
testcase_19 AC 133 ms
85,696 KB
testcase_20 AC 1,366 ms
98,556 KB
testcase_21 AC 1,475 ms
99,480 KB
testcase_22 AC 1,010 ms
93,624 KB
testcase_23 AC 1,018 ms
96,540 KB
testcase_24 AC 1,010 ms
96,196 KB
testcase_25 AC 1,027 ms
96,248 KB
testcase_26 AC 1,888 ms
106,292 KB
testcase_27 AC 1,895 ms
106,124 KB
testcase_28 AC 126 ms
85,508 KB
testcase_29 AC 1,599 ms
102,688 KB
testcase_30 AC 134 ms
85,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w = map(int,input().split())
s = [input() for i in range(h)]
now = 0
l = set([(0,0)])
ans = s[0][0]
while now < h+w-1:
  new = set()
  mn = "z"
  if (h-1, w-1) in l: break
  for i,j in l:
    if i == h-1:
      mn = min(mn, s[i][j+1])
    elif j == w-1:
      mn = min(mn, s[i+1][j])
    else:
      mn = min(mn, s[i][j+1], s[i+1][j])
  for i,j in l:
    if i == h-1:
      if s[i][j+1] == mn:
        new.add((i,j+1))
    elif j == w-1:
      if s[i+1][j] == mn:
        new.add((i+1,j))
    else:
      if s[i][j+1] == mn:
        new.add((i,j+1))
      if s[i+1][j] == mn:
        new.add((i+1,j))
  l = new
  now += 1
  ans += mn
print(ans)
  


     
0