結果

問題 No.1743 Permutation Code
ユーザー tnodinotnodino
提出日時 2022-04-21 04:58:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,479 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 10,760 KB
実行使用メモリ 12,692 KB
最終ジャッジ日時 2023-09-03 21:09:51
合計ジャッジ時間 12,160 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,264 KB
testcase_01 AC 18 ms
8,112 KB
testcase_02 AC 17 ms
8,144 KB
testcase_03 AC 18 ms
8,192 KB
testcase_04 AC 59 ms
8,272 KB
testcase_05 AC 18 ms
8,332 KB
testcase_06 AC 873 ms
8,200 KB
testcase_07 TLE -
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 operator1(C):
    M = len(C)
    cnt = 0
    for b in range(1,1<<16):
        cnt += len(bin(b)) - 2
        if cnt == M:
            return b, M, len(bin(b)) - 2

def operator2(C, N, M, B):
    Num = [[] for _ in range(N+1)]
    cnt = [0] * (N+1)
    for i in range(M):
        for b in range(1,B+1):
            if i + b - 1 >= M:
                break
            if i + b < M and C[i+b] == '0':
                continue
            c = int(C[i:i+b], 2)
            if c == 0 or c > N:
                break
            Num[c].append(i)
            cnt[c] += 1
    for i in range(N+1):
        cnt[i] = [cnt[i], i]
    cnt = cnt[1:]
    cnt.sort()
    return Num, cnt

def dfs(x):
    global N, Flg, ans, Num, cnt
    if x == N:
        for i in range(N+1):
            ans[i] = [ans[i], i]
        ans = ans[1:]
        ans.sort()
        for i in range(N):
            ans[i] = ans[i][1]
        print(*ans)
        exit()
    C = cnt[x][1]
    B = len(bin(C)) - 2
    for i in Num[C]:
        Flg2 = 1
        for b in range(B):
            if Flg[i+b]:
                Flg2 = 0
                break
        if Flg2:
            ans[C] = i
            for b in range(B):
                Flg[i+b] = 1
            dfs(x+1)
            ans[C] = 0
            for b in range(B):
                Flg[i+b] = 0

C = input()
N,M,B = operator1(C)
Num,cnt = operator2(C, N, M, B)
Flg = [0] * M
ans = [0] * (N+1)
dfs(0)
0