結果

問題 No.1743 Permutation Code
ユーザー noya2noya2
提出日時 2021-09-20 11:49:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,657 bytes
コンパイル時間 2,363 ms
コンパイル使用メモリ 215,168 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-05-07 15:55:48
合計ジャッジ時間 12,614 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 5 ms
5,376 KB
testcase_05 AC 18 ms
5,376 KB
testcase_06 AC 189 ms
5,376 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 #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
using namespace std;

template<class T>ostream &operator<<(ostream &os,const vector<T> &v){if(v.size()==0){os<<endl;}else{rep(i,v.size())os<<v[i]<<(i+1==v.size()?"\n":" ");}return os;}

string bin(int n){
    string ans = "";
    while (n > 0){
        int m = n % 2;
        ans += to_string(m);
        n /= 2;
    }
    reverse(ans.begin(),ans.end());
    return ans;
}

int num(string s){
    reverse(s.begin(),s.end());
    int ans = 0;
    int ni = 1;
    for (char c : s){
        if (c == '1') ans += ni;
        ni *= 2;
    }
    return ans;
}

set<int> used;
stack<int> now;
string code;
int leng;
int lim;

void saiki(int ind){
    if (ind == leng){
        vector<int> ans;
        while (!now.empty()){
            ans.emplace_back(now.top());
            now.pop();
        }
        reverse(ans.begin(),ans.end());
        cout << ans;
        exit(0);
    }
    string nows = "";
    repp(i,leng,ind){
        nows += code[i];
        int nown = num(nows);
        if (nown > lim) break;
        if (i + 1 == leng || code[i+1] == '1'){
            if (used.find(nown) == used.end()){
                used.insert(nown);
                now.push(nown);
                saiki(i+1);
                used.erase(nown);
                now.pop();
            }
        }
    }
}

int main(){
    string s; cin >> s;
    int n = 0;
    int siz = s.size();
    int tiz = 0;
    while (tiz < siz){
        n++;
        string z = bin(n);
        tiz += z.size();
    }
    code = s;
    leng = siz;
    lim = n;
    saiki(0);
}
0