結果

問題 No.2064 Smallest Sequence on Grid
コンテスト
ユーザー FromBooska
提出日時 2023-06-12 14:08:48
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 1,298 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 266 ms
コンパイル使用メモリ 95,840 KB
実行使用メモリ 119,040 KB
最終ジャッジ日時 2026-07-25 14:04:12
合計ジャッジ時間 7,137 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15 TLE * 1 -- * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# 最初のは実装も汚くTLEした
# dp的にできるように再配置しよう
# 辞書順最小だから前から決めていく
# 斜め線上にあるアルファベットで最小のものを全部残しその次のものからも最小を選ぶ

H, W = map(int, input().split())
S = []
for i in range(H):
    temp = input()
    S.append(temp)

S_reorganized = []
for i in range(H+W-1):
    temp = ''
    for j in range(H+W-1):
        if 0 <= i-j < H and 0 <= j < W:
            temp += S[i-j][j]
        else:
            temp += '{'
    S_reorganized.append(temp)

dp = [[0]*(H+W-1) for i in range(H+W-1)]
dp[0][0] = 1
alphabets = 'abcdefghijklmnopqrstuvwxyz'
ans = S_reorganized[0][0]

for i in range(1, H+W-1):
    smallest = '{' #辞書順最悪ダミー
    smallest_index = []
    for j in range(H+W-1):
        if dp[i-1][max(0, j-1)] == 1 or dp[i-1][j] == 1:
            if S_reorganized[i][j] == smallest:
                smallest_index.append(j)
            elif S_reorganized[i][j] < smallest:
                smallest = S_reorganized[i][j]
                smallest_index = []
                smallest_index.append(j)
    ans += smallest
    
    for j in smallest_index:
        dp[i][j] = 1
        
    #print(smallest, smallest_index)
    #print(dp[i])

print(ans)





0