結果

問題 No.2064 Smallest Sequence on Grid
ユーザー SidewaysOwlSidewaysOwl
提出日時 2022-09-03 17:42:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 1,209 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 828,416 KB
最終ジャッジ日時 2024-04-28 15:16:43
合計ジャッジ時間 7,197 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 29 ms
10,624 KB
testcase_03 AC 29 ms
10,880 KB
testcase_04 AC 30 ms
10,624 KB
testcase_05 AC 30 ms
10,880 KB
testcase_06 AC 30 ms
10,624 KB
testcase_07 AC 30 ms
10,880 KB
testcase_08 AC 32 ms
11,008 KB
testcase_09 AC 31 ms
11,008 KB
testcase_10 AC 37 ms
11,520 KB
testcase_11 AC 36 ms
11,392 KB
testcase_12 AC 35 ms
11,136 KB
testcase_13 AC 41 ms
11,264 KB
testcase_14 AC 48 ms
11,520 KB
testcase_15 AC 43 ms
11,264 KB
testcase_16 AC 46 ms
11,520 KB
testcase_17 MLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
from collections import defaultdict
d = defaultdict(list)
for i in range(h):
    for j in range(w):
        d[i+j].append((i,j))
        
vis = [[0] * w for _ in range(h)]
vis[0][0] = 1
vecs = [(0,1),(1,0)]
for key in sorted(d.keys()):
    if key == h + w - 2 :break
    mark = chr(123)
    for i,j in d[key]:
        if vis[i][j] == 1:
            for vi,vj in vecs:
                ni,nj = i + vi,j + vj
                if not (0 <= ni <= h-1 and 0 <= nj <= w-1):continue
                if mark > s[ni][nj]:
                    mark = s[ni][nj]
    for i,j in d[key]:
        if vis[i][j] == 1:
            for vi,vj in vecs:
                ni,nj = i + vi,j + vj
                if not (0 <= ni <= h-1 and 0 <= nj <= w-1):continue
                if mark == s[ni][nj]:
                    vis[ni][nj] = 1
ans = [s[h-1][w-1]]
from collections import deque
vecs = [(0,-1),(-1,0)]
i,j = h-1,w-1
while (i+j):
    for vi,vj in vecs:
        ni = i+vi
        nj = j+vj
        if not (0 <= ni <= h-1 and 0 <= nj <= w-1):continue
        if not vis[ni][nj]:continue
        i ,j = ni,nj
        ans.append(s[ni][nj])
print("".join(ans[::-1]))
0