結果
| 問題 |
No.1437 01 Sort
|
| ユーザー |
tyawanmusi
|
| 提出日時 | 2021-01-20 17:48:59 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 445 bytes |
| コンパイル時間 | 395 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 1,618,864 KB |
| 最終ジャッジ日時 | 2024-11-25 20:57:07 |
| 合計ジャッジ時間 | 39,194 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 MLE * 1 |
| other | AC * 10 TLE * 13 MLE * 1 |
ソースコード
# 計算量 O(いっぱい)
from collections import defaultdict, deque
n = int(input())
s = input()
cost = defaultdict(int)
cost[s] = 0
goal = "".join(sorted(list(s)))
que = deque([s])
while que:
t = que.popleft()
if t == goal:
exit(print(cost[t]))
t1 = t[-1] + t[:-1]
t2 = t[0] + t[-1] + t[1:-1]
if t1 not in cost:
cost[t1] = cost[t] + 1
que.append(t1)
if t2 not in cost:
cost[t2] = cost[t] + 1
que.append(t2)
tyawanmusi