結果

問題 No.2064 Smallest Sequence on Grid
ユーザー ygd.ygd.
提出日時 2022-09-02 21:52:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,482 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 81,652 KB
実行使用メモリ 848,764 KB
最終ジャッジ日時 2024-04-27 21:23:32
合計ジャッジ時間 5,620 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,308 KB
testcase_01 AC 39 ms
52,272 KB
testcase_02 AC 38 ms
52,616 KB
testcase_03 AC 39 ms
52,280 KB
testcase_04 AC 39 ms
52,272 KB
testcase_05 AC 38 ms
52,424 KB
testcase_06 AC 40 ms
53,080 KB
testcase_07 AC 38 ms
52,532 KB
testcase_08 AC 40 ms
52,828 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 60 ms
75,936 KB
testcase_14 MLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
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 #

import sys
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline #文字列はダメ
#sys.setrecursionlimit(1000000)
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict 
#from collections import deque
#import copy #DeepCopy: hoge = [_[:] for _ in hogehoge]
#import math
#from functools import lru_cache
#@lru_cache(maxsize=None)
#MOD = pow(10,9) + 7
MOD = 998244353
#dx = [1,0,-1,0]
#dy = [0,1,0,-1]
#dx8 = [1,1,0,-1,-1,-1,0,1]
#dy8 = [0,1,1,1,0,-1,-1,-1]

def main():
    H,W = map(int,input().split())
    S = [input() for _ in range(H)]

    ans = [S[0][0]]
    stack = []
    stack.append((S[0][0],0))
    cnt = 0
    while cnt < H+W-2:
        mn = 'zz'
        while stack:
            v,idx = stack.pop()
            x = idx//W
            y = idx%W
            for i in range(2):
                if i == 0:
                    if x+1 >= H: continue
                    nv = S[x+1][y]
                    nidx = (x+1)*W + y
                else:
                    if y+1 >= W: continue
                    nv = S[x][y+1]
                    nidx = x*W + y+1
                if nv < mn:
                    mn = nv
                    ok = [(nv,nidx)] 
                elif v == mn:
                    ok.append((nv,nidx))
        cnt += 1
        ans.append(mn)
        stack = ok
        # print(stack)
    print("".join(ans))

                

if __name__ == '__main__':
    main()
0