結果

問題 No.2064 Smallest Sequence on Grid
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-09-02 22:12:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,066 ms / 3,000 ms
コード長 708 bytes
コンパイル時間 773 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 178,400 KB
最終ジャッジ日時 2023-08-10 04:17:31
合計ジャッジ時間 12,848 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,640 KB
testcase_01 AC 71 ms
71,520 KB
testcase_02 AC 71 ms
71,392 KB
testcase_03 AC 68 ms
71,472 KB
testcase_04 AC 70 ms
71,568 KB
testcase_05 AC 68 ms
71,352 KB
testcase_06 AC 67 ms
71,480 KB
testcase_07 AC 70 ms
71,144 KB
testcase_08 AC 77 ms
76,116 KB
testcase_09 AC 74 ms
75,220 KB
testcase_10 AC 77 ms
75,980 KB
testcase_11 AC 75 ms
75,996 KB
testcase_12 AC 75 ms
76,020 KB
testcase_13 AC 79 ms
76,472 KB
testcase_14 AC 81 ms
76,360 KB
testcase_15 AC 81 ms
76,420 KB
testcase_16 AC 81 ms
76,512 KB
testcase_17 AC 236 ms
157,504 KB
testcase_18 AC 231 ms
157,760 KB
testcase_19 AC 227 ms
157,336 KB
testcase_20 AC 801 ms
169,192 KB
testcase_21 AC 863 ms
171,424 KB
testcase_22 AC 625 ms
164,100 KB
testcase_23 AC 654 ms
167,912 KB
testcase_24 AC 650 ms
167,852 KB
testcase_25 AC 650 ms
167,896 KB
testcase_26 AC 1,066 ms
178,380 KB
testcase_27 AC 1,063 ms
178,400 KB
testcase_28 AC 233 ms
157,364 KB
testcase_29 AC 879 ms
161,624 KB
testcase_30 AC 236 ms
150,792 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