結果

問題 No.2064 Smallest Sequence on Grid
ユーザー SidewaysOwlSidewaysOwl
提出日時 2022-09-03 18:05:52
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,197 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 82,224 KB
実行使用メモリ 849,196 KB
最終ジャッジ日時 2024-04-28 15:33:42
合計ジャッジ時間 6,235 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,548 KB
testcase_01 AC 39 ms
54,612 KB
testcase_02 AC 38 ms
53,800 KB
testcase_03 AC 39 ms
55,180 KB
testcase_04 AC 37 ms
54,320 KB
testcase_05 AC 38 ms
54,792 KB
testcase_06 AC 37 ms
54,340 KB
testcase_07 AC 39 ms
55,928 KB
testcase_08 AC 46 ms
62,328 KB
testcase_09 AC 49 ms
63,512 KB
testcase_10 AC 49 ms
65,260 KB
testcase_11 AC 55 ms
66,880 KB
testcase_12 AC 56 ms
66,336 KB
testcase_13 AC 60 ms
70,688 KB
testcase_14 AC 58 ms
68,392 KB
testcase_15 AC 62 ms
67,856 KB
testcase_16 AC 62 ms
68,852 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)]
d = [[] for _ in range(w+h-1)]
for i in range(h):
    for j in range(w):
#         print(d)
        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 range(w+h-1):
    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