結果

問題 No.1743 Permutation Code
ユーザー FplusFplusFFplusFplusF
提出日時 2022-11-29 22:24:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,680 bytes
コンパイル時間 2,752 ms
コンパイル使用メモリ 207,740 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-04-16 13:27:51
合計ジャッジ時間 12,550 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,912 KB
testcase_01 AC 5 ms
6,784 KB
testcase_02 AC 5 ms
6,784 KB
testcase_03 AC 8 ms
6,784 KB
testcase_04 AC 84 ms
6,912 KB
testcase_05 AC 199 ms
6,784 KB
testcase_06 TLE -
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 #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
const ll INF=(1ll<<60);
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
string ten_to_two(int x){
    string s;
    while(0<x){
        s.push_back(x%2+'0');
        x/=2;
    }
    reverse(all(s));
    return s;
}
int n=0,k=0;
string s[(1<<16)];
bool used[(1<<16)];
vector<vector<int>> v((1<<16));
int per[(1<<16)];
vector<pair<int,int>> ans;
void dfs(int p){
    if(n<=p){
        sort(all(ans));
        rep(i,n){
            cout << ans[i].second << " ";
        }
        cout << endl;
        exit(0);
    }
    for(auto &i:v[per[p]]){
        bool ok=true;
        for(int j=i;j<i+(int)s[per[p]].size();j++){
            if(used[j]){
                ok=false;
                break;
            }
        }
        if(!ok) continue;
        for(int j=i;j<i+(int)s[per[p]].size();j++) used[j]=true;
        ans.emplace_back(i,per[p]);
        dfs(p+1);
        ans.pop_back();
        for(int j=i;j<i+(int)s[per[p]].size();j++) used[j]=false;
    }
}
int main(){
    string c;
    cin >> c;
    k=c.size();
    int x=0;
    while(x<k){
        s[n]=ten_to_two(n);
        x+=s[n].size();
        n++;
    }
    n--;
    vector<pair<int,int>> vp(n);
    for(int i=1;i<=n;i++){
        rep(j,k-s[i].size()+1){
            if(s[i]==c.substr(j,s[i].size())) v[i].push_back(j);
        }
        vp[i-1]={n-i,i};
    }
    sort(all(vp));
    rep(i,n) per[i]=vp[i].second;
    dfs(0);
}
0