結果

問題 No.2064 Smallest Sequence on Grid
ユーザー FromBooskaFromBooska
提出日時 2023-06-12 14:08:48
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,298 bytes
コンパイル時間 1,627 ms
コンパイル使用メモリ 86,352 KB
実行使用メモリ 76,580 KB
最終ジャッジ日時 2023-09-02 09:16:26
合計ジャッジ時間 13,597 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,384 KB
testcase_01 AC 70 ms
71,424 KB
testcase_02 AC 70 ms
71,600 KB
testcase_03 AC 70 ms
71,056 KB
testcase_04 AC 72 ms
71,340 KB
testcase_05 AC 71 ms
71,056 KB
testcase_06 AC 71 ms
71,052 KB
testcase_07 AC 69 ms
71,296 KB
testcase_08 AC 90 ms
76,520 KB
testcase_09 AC 81 ms
76,168 KB
testcase_10 AC 84 ms
76,268 KB
testcase_11 AC 84 ms
76,516 KB
testcase_12 AC 85 ms
76,452 KB
testcase_13 AC 90 ms
76,504 KB
testcase_14 AC 90 ms
76,484 KB
testcase_15 AC 89 ms
76,484 KB
testcase_16 AC 87 ms
76,580 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 #

# 最初のは実装も汚く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