結果
| 問題 | No.205 マージして辞書順最小 |
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-31 17:52:42 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 951 bytes |
| 記録 | |
| コンパイル時間 | 233 ms |
| コンパイル使用メモリ | 96,104 KB |
| 実行使用メモリ | 1,332,788 KB |
| 最終ジャッジ日時 | 2026-07-08 05:29:15 |
| 合計ジャッジ時間 | 7,151 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | AC * 2 MLE * 2 -- * 11 |
ソースコード
import sys
from functools import lru_cache
def main():
sys.setrecursionlimit(1 << 25)
n = int(sys.stdin.readline())
strings = [sys.stdin.readline().strip() for _ in range(n)]
@lru_cache(maxsize=None)
def dfs(state):
remaining = [s for s in state if s]
if not remaining:
return ''
first_chars = [s[0] for s in remaining]
min_char = min(first_chars)
candidates_indices = [i for i, s in enumerate(state) if s and s[0] == min_char]
min_str = None
for idx in candidates_indices:
new_state = list(state)
new_state[idx] = new_state[idx][1:]
new_state_tuple = tuple(new_state)
res = min_char + dfs(new_state_tuple)
if min_str is None or res < min_str:
min_str = res
return min_str
initial_state = tuple(strings)
print(dfs(initial_state))
if __name__ == '__main__':
main()
lam6er