結果

問題 No.2064 Smallest Sequence on Grid
ユーザー mkawa2mkawa2
提出日時 2023-03-09 12:42:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,692 ms / 3,000 ms
コード長 1,606 bytes
コンパイル時間 980 ms
コンパイル使用メモリ 81,856 KB
実行使用メモリ 246,608 KB
最終ジャッジ日時 2023-10-18 06:14:58
合計ジャッジ時間 17,873 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,436 KB
testcase_01 AC 38 ms
53,436 KB
testcase_02 AC 38 ms
53,436 KB
testcase_03 AC 38 ms
53,436 KB
testcase_04 AC 38 ms
53,436 KB
testcase_05 AC 38 ms
53,436 KB
testcase_06 AC 39 ms
53,436 KB
testcase_07 AC 38 ms
53,436 KB
testcase_08 AC 43 ms
59,236 KB
testcase_09 AC 42 ms
59,236 KB
testcase_10 AC 43 ms
59,240 KB
testcase_11 AC 43 ms
59,236 KB
testcase_12 AC 43 ms
59,236 KB
testcase_13 AC 50 ms
64,140 KB
testcase_14 AC 51 ms
64,140 KB
testcase_15 AC 50 ms
64,252 KB
testcase_16 AC 50 ms
64,140 KB
testcase_17 AC 551 ms
246,020 KB
testcase_18 AC 533 ms
246,164 KB
testcase_19 AC 504 ms
246,524 KB
testcase_20 AC 1,219 ms
246,392 KB
testcase_21 AC 1,328 ms
246,400 KB
testcase_22 AC 1,017 ms
246,408 KB
testcase_23 AC 999 ms
246,408 KB
testcase_24 AC 1,000 ms
246,412 KB
testcase_25 AC 1,015 ms
246,608 KB
testcase_26 AC 1,523 ms
246,388 KB
testcase_27 AC 1,692 ms
246,388 KB
testcase_28 AC 545 ms
246,388 KB
testcase_29 AC 1,491 ms
246,408 KB
testcase_30 AC 500 ms
246,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(300005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = 4294967295
md = 10**9+7
# md = 998244353

def solve():
    h, w = LI()
    ss = [ord(c) for _ in range(h) for c in SI()]
    ans = [ss[0]]
    now = set()
    now.add(0)
    for _ in range(h+w-2):
        mn = 1000
        nxt = set()
        while now:
            def push(nij):
                nonlocal mn, nxt
                s = ss[nij]
                if s == mn: nxt.add(nij)
                if s < mn:
                    nxt = set([nij])
                    mn = s

            ij = now.pop()
            i, j = divmod(ij, w)
            if i+1 < h:
                push(ij+w)
            if j+1 < w:
                push(ij+1)
        ans.append(mn)
        now = nxt

    print("".join(chr(c) for c in ans))

# ***************************************

# testnumber = II()
testnumber = 1
for testcase in range(testnumber):
    solve()
    # print("YES" if solve() else "NO")
    # print("Yes" if solve() else "No")
0