結果

問題 No.2064 Smallest Sequence on Grid
ユーザー SidewaysOwlSidewaysOwl
提出日時 2022-09-03 17:51:54
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,149 bytes
コンパイル時間 420 ms
コンパイル使用メモリ 82,444 KB
実行使用メモリ 509,896 KB
最終ジャッジ日時 2024-04-28 15:24:49
合計ジャッジ時間 29,891 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
60,152 KB
testcase_01 AC 40 ms
52,884 KB
testcase_02 AC 40 ms
53,208 KB
testcase_03 AC 39 ms
52,152 KB
testcase_04 AC 40 ms
53,612 KB
testcase_05 AC 40 ms
52,156 KB
testcase_06 AC 40 ms
54,008 KB
testcase_07 AC 39 ms
53,060 KB
testcase_08 AC 55 ms
63,004 KB
testcase_09 AC 54 ms
62,960 KB
testcase_10 AC 58 ms
65,464 KB
testcase_11 AC 66 ms
68,464 KB
testcase_12 AC 68 ms
67,620 KB
testcase_13 AC 74 ms
70,792 KB
testcase_14 AC 69 ms
68,560 KB
testcase_15 AC 66 ms
68,376 KB
testcase_16 AC 67 ms
68,712 KB
testcase_17 AC 1,380 ms
503,556 KB
testcase_18 AC 1,346 ms
503,560 KB
testcase_19 AC 1,354 ms
503,420 KB
testcase_20 TLE -
testcase_21 TLE -
testcase_22 AC 2,724 ms
503,592 KB
testcase_23 AC 2,838 ms
503,168 KB
testcase_24 AC 2,807 ms
502,976 KB
testcase_25 AC 2,876 ms
503,712 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 = '{'
    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