結果

問題 No.2064 Smallest Sequence on Grid
ユーザー ThetaTheta
提出日時 2022-12-12 19:34:59
言語 Python3
(3.11.2 + numpy 1.24.2 + scipy 1.10.1)
結果
WA  
実行時間 -
コード長 1,587 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 11,032 KB
実行使用メモリ 11,500 KB
最終ジャッジ日時 2023-08-06 14:59:28
合計ジャッジ時間 7,752 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
11,264 KB
testcase_01 AC 46 ms
11,168 KB
testcase_02 AC 46 ms
11,108 KB
testcase_03 AC 45 ms
11,272 KB
testcase_04 AC 44 ms
11,164 KB
testcase_05 AC 47 ms
11,168 KB
testcase_06 AC 47 ms
11,244 KB
testcase_07 AC 47 ms
11,172 KB
testcase_08 WA -
testcase_09 AC 49 ms
11,436 KB
testcase_10 AC 54 ms
11,400 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 57 ms
11,468 KB
testcase_15 AC 53 ms
11,500 KB
testcase_16 AC 56 ms
11,336 KB
testcase_17 TLE -
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 #

from dataclasses import dataclass, field
from typing import Optional


@dataclass
class MinimumManager:
    value: Optional[str] = None
    idxes: set[int] = field(default_factory=set)


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

    step_letters = []
    for idx_sum in range(H+W-1):
        step_letters.append([])
        for idx_height in range(idx_sum+1):
            try:
                step_letters[-1].append(letters[idx_height]
                                        [idx_sum-idx_height])
            except IndexError:
                pass

    strings = ""
    current_idx = set((0,))
    for step_idx, step_letter in enumerate(step_letters):
        minimum = MinimumManager()
        for idx in current_idx:
            if minimum.value is None:
                minimum.value = step_letter[idx]
                minimum.idxes = set((idx, ))
                continue

            if minimum.value == step_letter[idx]:
                minimum.idxes.add(idx)
            elif minimum.value > step_letter[idx]:
                minimum.value = step_letter[idx]
                minimum.idxes = set((idx,))
        strings += minimum.value

        current_idx = set()
        for idx in minimum.idxes:
            if step_idx < max(W, H) - 1:
                current_idx.add(idx)
                current_idx.add(min(idx+1, min(H, W)-1))
            else:
                current_idx.add(min(idx, len(step_letter)-2))
                current_idx.add(max(idx-1, 0))

    print(strings)


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