結果

問題 No.2064 Smallest Sequence on Grid
ユーザー flygonflygon
提出日時 2022-09-18 23:27:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,857 ms / 3,000 ms
コード長 658 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 87,024 KB
実行使用メモリ 106,924 KB
最終ジャッジ日時 2023-08-23 18:25:37
合計ジャッジ時間 17,195 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,332 KB
testcase_01 AC 71 ms
71,276 KB
testcase_02 AC 69 ms
71,180 KB
testcase_03 AC 71 ms
71,280 KB
testcase_04 AC 72 ms
71,460 KB
testcase_05 AC 68 ms
71,256 KB
testcase_06 AC 72 ms
71,392 KB
testcase_07 AC 71 ms
71,152 KB
testcase_08 AC 73 ms
71,476 KB
testcase_09 AC 70 ms
71,144 KB
testcase_10 AC 70 ms
71,512 KB
testcase_11 AC 83 ms
71,212 KB
testcase_12 AC 74 ms
71,276 KB
testcase_13 AC 83 ms
76,368 KB
testcase_14 AC 84 ms
76,620 KB
testcase_15 AC 84 ms
76,588 KB
testcase_16 AC 83 ms
76,704 KB
testcase_17 AC 161 ms
86,968 KB
testcase_18 AC 161 ms
86,864 KB
testcase_19 AC 162 ms
87,256 KB
testcase_20 AC 1,381 ms
99,160 KB
testcase_21 AC 1,460 ms
100,776 KB
testcase_22 AC 1,038 ms
95,556 KB
testcase_23 AC 1,020 ms
96,740 KB
testcase_24 AC 1,007 ms
97,052 KB
testcase_25 AC 1,018 ms
96,644 KB
testcase_26 AC 1,853 ms
106,924 KB
testcase_27 AC 1,857 ms
106,700 KB
testcase_28 AC 156 ms
86,616 KB
testcase_29 AC 1,566 ms
103,800 KB
testcase_30 AC 164 ms
86,072 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