結果

問題 No.1743 Permutation Code
ユーザー tnodinotnodino
提出日時 2022-04-20 06:41:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,052 bytes
コンパイル時間 617 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 16,244 KB
最終ジャッジ日時 2023-09-02 00:08:27
合計ジャッジ時間 16,809 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
16,244 KB
testcase_01 AC 20 ms
8,096 KB
testcase_02 AC 35 ms
8,196 KB
testcase_03 AC 128 ms
8,120 KB
testcase_04 AC 4,200 ms
8,148 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import setrecursionlimit
setrecursionlimit(10**6)

def dfs(x):
    global ans, flg
    if x == 0:
        for i in range(N+1):
            ans[i] = [ans[i], i]
        ans = ans[1:]
        ans.sort()
        ans2 = []
        for i in range(N):
            ans2.append(ans[i][1])
        print(*ans2)
        exit()
    for i, b in D[x]:
        flg2 = True
        for k in range(i,i+b):
            if flg[k]:
                flg2 = False
                break
        if flg2:
            ans[x] = i
            for k in range(i,i+b):
                flg[k] = 1
            dfs(x-1)
            ans[x] = 0
            for k in range(i,i+b):
                flg[k] = 0

C = input()
cnt = 0
M = len(C)
for i in range(1,1<<16):
    cnt += len(bin(i)) - 2
    if cnt == M:
        N = i
        break
B = len(bin(N)) - 2
D = [[] for _ in range(N+1)]
for b in range(1,B+1):
    for i in range(M-b+1):
        c = int(C[i:i+b], 2)
        if c <= N and len(bin(c)) - 2 == b:
            D[c].append((i, b))
ans = [0] * (N+1)
flg = [0] * M
dfs(N)
0