結果

問題 No.1743 Permutation Code
ユーザー harurun
提出日時 2026-07-09 04:01:22
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,061 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,709 ms
コンパイル使用メモリ 214,644 KB
実行使用メモリ 9,136 KB
最終ジャッジ日時 2026-07-09 04:01:41
合計ジャッジ時間 13,391 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 TLE * 1 -- * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

string C;
int L, N, M;
vector<int> ans;
vector<int> used;

int total_len(int n) {
    int s = 0;
    for (int i = 1; i <= n; i++) {
        s += 32 - __builtin_clz(i);
    }
    return s;
}

bool dfs(int pos) {
    if (pos == L) {
        return (int)ans.size() == N;
    }
    if (C[pos] != '1') return false;

    int v = 0;
    for (int len = 1; len <= M && pos + len <= L; len++) {
        v = v * 2 + (C[pos + len - 1] - '0');

        if (pos + len < L && C[pos + len] != '1') continue;
        if (v < 1 || v > N) continue;
        if (used[v]) continue;

        used[v] = 1;
        ans.push_back(v);

        if (dfs(pos + len)) return true;

        ans.pop_back();
        used[v] = 0;
    }
    return false;
}

int main() {
    cin >> C;
    L = C.size();

    N = 1;
    while (total_len(N) < L) N++;

    M = 32 - __builtin_clz(N);
    used.assign(N + 1, 0);

    dfs(0);

    for (int i = 0; i < (int)ans.size(); i++) {
        if (i) cout << ' ';
        cout << ans[i];
    }
    cout << '\n';
}
0