結果

問題 No.2064 Smallest Sequence on Grid
ユーザー first_vilfirst_vil
提出日時 2022-09-02 21:57:39
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 2,067 ms / 3,000 ms
コード長 1,254 bytes
コンパイル時間 327 ms
コンパイル使用メモリ 87,312 KB
実行使用メモリ 331,132 KB
最終ジャッジ日時 2023-08-10 03:58:32
合計ジャッジ時間 25,586 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,272 KB
testcase_01 AC 66 ms
71,540 KB
testcase_02 AC 69 ms
71,452 KB
testcase_03 AC 69 ms
71,612 KB
testcase_04 AC 71 ms
71,628 KB
testcase_05 AC 69 ms
71,368 KB
testcase_06 AC 68 ms
71,492 KB
testcase_07 AC 68 ms
71,488 KB
testcase_08 AC 80 ms
76,012 KB
testcase_09 AC 76 ms
76,584 KB
testcase_10 AC 80 ms
76,028 KB
testcase_11 AC 82 ms
76,616 KB
testcase_12 AC 81 ms
76,352 KB
testcase_13 AC 87 ms
76,744 KB
testcase_14 AC 86 ms
76,564 KB
testcase_15 AC 84 ms
76,768 KB
testcase_16 AC 86 ms
76,648 KB
testcase_17 AC 1,110 ms
330,472 KB
testcase_18 AC 1,085 ms
330,812 KB
testcase_19 AC 1,086 ms
330,852 KB
testcase_20 AC 1,806 ms
330,856 KB
testcase_21 AC 1,870 ms
330,852 KB
testcase_22 AC 1,681 ms
330,792 KB
testcase_23 AC 1,694 ms
330,724 KB
testcase_24 AC 1,698 ms
330,608 KB
testcase_25 AC 1,715 ms
330,964 KB
testcase_26 AC 2,049 ms
330,600 KB
testcase_27 AC 2,067 ms
331,132 KB
testcase_28 AC 1,100 ms
330,736 KB
testcase_29 AC 1,612 ms
313,032 KB
testcase_30 AC 951 ms
310,620 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