結果

問題 No.2064 Smallest Sequence on Grid
ユーザー SidewaysOwlSidewaysOwl
提出日時 2022-09-03 17:49:49
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,154 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 556,924 KB
最終ジャッジ日時 2024-04-28 15:23:28
合計ジャッジ時間 30,994 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 39 ms
52,680 KB
testcase_02 AC 39 ms
53,200 KB
testcase_03 AC 38 ms
53,076 KB
testcase_04 AC 41 ms
53,844 KB
testcase_05 AC 39 ms
53,500 KB
testcase_06 AC 38 ms
52,616 KB
testcase_07 AC 40 ms
52,404 KB
testcase_08 AC 56 ms
64,048 KB
testcase_09 AC 56 ms
64,388 KB
testcase_10 AC 57 ms
65,960 KB
testcase_11 AC 66 ms
67,852 KB
testcase_12 AC 66 ms
68,328 KB
testcase_13 AC 74 ms
71,220 KB
testcase_14 AC 72 ms
68,648 KB
testcase_15 AC 68 ms
68,408 KB
testcase_16 AC 68 ms
68,744 KB
testcase_17 AC 1,526 ms
503,372 KB
testcase_18 AC 1,715 ms
503,764 KB
testcase_19 AC 1,325 ms
503,504 KB
testcase_20 TLE -
testcase_21 TLE -
testcase_22 AC 2,741 ms
503,156 KB
testcase_23 AC 2,811 ms
503,516 KB
testcase_24 AC 2,823 ms
503,588 KB
testcase_25 AC 2,763 ms
503,716 KB
testcase_26 TLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
vis = [[0] * w for _ in range(h)]
vis[0][0] = 1
vecs = [(0,1),(1,0)]
for n in range(h+w):
    mark = chr(123)
    for i in range(n+1):
        j = n-i
        if not (0 <= i <= h-1 and 0 <= j <= w-1):continue
        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 in range(n+1):
        j = n-i
        if not (0 <= i <= h-1 and 0 <= j <= w-1):continue
        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]]
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