結果

問題 No.2064 Smallest Sequence on Grid
ユーザー first_vilfirst_vil
提出日時 2022-09-02 21:57:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,862 ms / 3,000 ms
コード長 1,254 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 82,516 KB
実行使用メモリ 328,612 KB
最終ジャッジ日時 2024-04-27 21:30:26
合計ジャッジ時間 21,964 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
52,524 KB
testcase_01 AC 34 ms
54,012 KB
testcase_02 AC 34 ms
53,200 KB
testcase_03 AC 32 ms
53,792 KB
testcase_04 AC 33 ms
52,612 KB
testcase_05 AC 32 ms
52,888 KB
testcase_06 AC 32 ms
54,024 KB
testcase_07 AC 32 ms
52,724 KB
testcase_08 AC 38 ms
60,140 KB
testcase_09 AC 38 ms
62,272 KB
testcase_10 AC 40 ms
63,044 KB
testcase_11 AC 45 ms
64,528 KB
testcase_12 AC 44 ms
63,044 KB
testcase_13 AC 52 ms
65,428 KB
testcase_14 AC 46 ms
66,432 KB
testcase_15 AC 48 ms
65,448 KB
testcase_16 AC 49 ms
65,588 KB
testcase_17 AC 965 ms
328,108 KB
testcase_18 AC 952 ms
328,612 KB
testcase_19 AC 955 ms
328,108 KB
testcase_20 AC 1,659 ms
328,368 KB
testcase_21 AC 1,690 ms
328,204 KB
testcase_22 AC 1,514 ms
328,368 KB
testcase_23 AC 1,539 ms
328,492 KB
testcase_24 AC 1,552 ms
328,360 KB
testcase_25 AC 1,519 ms
328,212 KB
testcase_26 AC 1,856 ms
328,240 KB
testcase_27 AC 1,862 ms
328,368 KB
testcase_28 AC 951 ms
328,524 KB
testcase_29 AC 1,405 ms
309,216 KB
testcase_30 AC 802 ms
310,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
import sys

int1 = lambda x: int(x) - 1

# input = lambda: sys.stdin.buffer.readline()
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
i1 = lambda: int1(input())
mi = lambda: map(int, input().split())
mi1 = lambda: map(int1, input().split())
li = lambda: list(mi())
li1 = lambda: list(mi1())
lli = lambda n: [li() for _ in range(n)]

INF = float("inf")
mod = int(1e9 + 7)
# mod = 998244353

h, w = mi()
s = [input() for i in range(h)]
ans = [s[0][0]]
e = chr(ord("z") + 1)
d = [list() for i in range(h + w - 1)]
for y in range(h):
    for x in range(w):
        d[y + x].append(y * w + x)
f = [[False] * w for i in range(h)]
f[0][0] = True
for i in range(h + w - 2):
    mn = e
    for tmp in d[i]:
        y, x = tmp // w, tmp % w
        if not f[y][x]:
            continue
        if y + 1 < h and mn > s[y + 1][x]:
            mn = s[y + 1][x]
        if x + 1 < w and mn > s[y][x + 1]:
            mn = s[y][x + 1]
    ans.append(mn)
    for tmp in d[i]:
        y, x = tmp // w, tmp % w
        if not f[y][x]:
            continue
        if y + 1 < h and s[y + 1][x] == mn:
            f[y + 1][x] = True
        if x + 1 < w and s[y][x + 1] == mn:
            f[y][x + 1] = True
print("".join(ans))
0