結果

問題 No.2064 Smallest Sequence on Grid
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-09-02 22:12:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 851 ms / 3,000 ms
コード長 708 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 82,028 KB
実行使用メモリ 177,528 KB
最終ジャッジ日時 2024-04-27 21:47:45
合計ジャッジ時間 9,276 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
52,744 KB
testcase_01 AC 31 ms
52,760 KB
testcase_02 AC 32 ms
52,076 KB
testcase_03 AC 34 ms
52,528 KB
testcase_04 AC 31 ms
52,552 KB
testcase_05 AC 35 ms
53,532 KB
testcase_06 AC 33 ms
53,428 KB
testcase_07 AC 34 ms
53,216 KB
testcase_08 AC 39 ms
59,420 KB
testcase_09 AC 33 ms
58,800 KB
testcase_10 AC 37 ms
59,832 KB
testcase_11 AC 38 ms
60,292 KB
testcase_12 AC 39 ms
61,240 KB
testcase_13 AC 40 ms
61,644 KB
testcase_14 AC 43 ms
64,480 KB
testcase_15 AC 42 ms
63,352 KB
testcase_16 AC 43 ms
63,028 KB
testcase_17 AC 168 ms
156,228 KB
testcase_18 AC 171 ms
156,248 KB
testcase_19 AC 172 ms
156,184 KB
testcase_20 AC 636 ms
167,628 KB
testcase_21 AC 686 ms
170,308 KB
testcase_22 AC 462 ms
162,420 KB
testcase_23 AC 523 ms
166,412 KB
testcase_24 AC 518 ms
166,280 KB
testcase_25 AC 530 ms
166,424 KB
testcase_26 AC 851 ms
177,528 KB
testcase_27 AC 846 ms
177,504 KB
testcase_28 AC 169 ms
156,000 KB
testcase_29 AC 685 ms
159,396 KB
testcase_30 AC 172 ms
150,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w = map(int,input().split())
S = [input() for i in range(h)]
ans = []
vis = [[0]*w for i in range(h)]
ans.append(S[0][0])
l = [[0,0]]

for i in range(h+w-1):

    cands = [[] for j in range(26)]
    for x,y in l:
        nx,ny = x+1,y
        if 0 <= nx < h and 0 <= ny < w and vis[nx][ny] == 0:
            cands[ord(S[nx][ny])-ord("a")].append([nx,ny])
            vis[nx][ny] = 1

        nx,ny = x,y+1
        if 0 <= nx < h and 0 <= ny < w and vis[nx][ny] == 0:
            cands[ord(S[nx][ny])-ord("a")].append([nx,ny])
            vis[nx][ny] = 1
    for j in range(26):
        if cands[j] != []:
            l = cands[j]
            ans.append(chr(j+ord("a")))
            break
print(*ans,sep="")
0