結果
| 問題 |
No.1743 Permutation Code
|
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 20:47:00 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,502 bytes |
| コンパイル時間 | 234 ms |
| コンパイル使用メモリ | 81,748 KB |
| 実行使用メモリ | 92,040 KB |
| 最終ジャッジ日時 | 2025-06-12 20:47:55 |
| 合計ジャッジ時間 | 11,817 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 TLE * 1 -- * 23 |
ソースコード
import sys
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(1 << 25)
def compute_n(c_length):
total = 0
n = 0
while True:
n += 1
bits = n.bit_length()
total += bits
if total == c_length:
return n
elif total > c_length:
return -1
def main():
C = stdin.read().strip()
c_length = len(C)
N = compute_n(c_length)
if N == -1:
print("Invalid input")
return
binary_strings = []
for num in range(1, N+1):
binary_strings.append(bin(num)[2:])
binary_dict = {bs: num for num, bs in enumerate(binary_strings, 1)}
used = [False] * (N+1)
path = []
found = False
def backtrack(pos):
nonlocal found
if pos == len(C):
if all(used[1:]):
return True
return False
if found:
return True
for l in range(1, len(C)-pos +1):
current_bs = C[pos:pos+l]
if current_bs in binary_dict:
num = binary_dict[current_bs]
if not used[num]:
used[num] = True
if backtrack(pos + l):
path.append(num)
return True
used[num] = False
return False
if backtrack(0):
path.reverse()
print(' '.join(map(str, path)))
else:
print("No solution found")
if __name__ == "__main__":
main()
gew1fw