結果
| 問題 |
No.1743 Permutation Code
|
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 20:47:24 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,736 bytes |
| コンパイル時間 | 250 ms |
| コンパイル使用メモリ | 82,264 KB |
| 実行使用メモリ | 111,044 KB |
| 最終ジャッジ日時 | 2025-06-12 20:48:58 |
| 合計ジャッジ時間 | 11,901 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 TLE * 1 -- * 22 |
ソースコード
def solve():
import sys
C = sys.stdin.read().strip()
L = len(C)
def compute_sum(N):
s = 0
k = 1
while True:
lower = 2 ** (k-1)
upper = 2 ** k - 1
if lower > N:
break
current_upper = min(upper, N)
count = current_upper - lower + 1
s += count * k
k += 1
return s
low = 1
high = 10**6 # Arbitrary large upper bound
found = False
N = 0
while low <= high:
mid = (low + high) // 2
s = compute_sum(mid)
if s == L:
N = mid
found = True
break
elif s < L:
low = mid + 1
else:
high = mid - 1
binaries = {i: bin(i)[2:] for i in range(1, N+1)}
result = None
used = set()
current = []
def backtrack(pos):
nonlocal result
if result is not None:
return
if pos == len(C):
if len(current) == N:
result = current.copy()
return
max_try = min(10, len(C) - pos)
for length in range(1, max_try + 1):
if pos + length > len(C):
continue
substr = C[pos:pos+length]
if substr[0] != '1':
continue
num = int(substr, 2)
if 1 <= num <= N and num not in used:
used.add(num)
current.append(num)
backtrack(pos + length)
if result is not None:
return
current.pop()
used.remove(num)
backtrack(0)
print(' '.join(map(str, result)) + '\n')
solve()
gew1fw