結果

問題 No.1743 Permutation Code
ユーザー FplusFplusFFplusFplusF
提出日時 2022-12-01 00:49:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,423 bytes
コンパイル時間 2,487 ms
コンパイル使用メモリ 206,996 KB
実行使用メモリ 10,172 KB
最終ジャッジ日時 2024-04-16 19:05:46
合計ジャッジ時間 34,687 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 TLE -
testcase_24 TLE -
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 main(){
    string c;
    cin >> c;
    int k=c.size();
    int n=0,sum=0;
    while(sum<k){
        sum+=ten_to_two(n).size();
        n++;
    }
    n--;
    vector<string> s(n+1);
    for(int i=1;i<=n;i++){
        s[i]=ten_to_two(i);
    }
    vector<pair<int,int>> ans;
    vector<bool> used(k,false);
    for(int i=n;1<=i;i--){
        int z=s[i].size();
        rep(j,k-z+1){
            bool t=true;
            for(int ii=j;ii<j+z;ii++){
                if(used[ii]){
                    t=false;
                    break;
                }
            }
            if(!t) continue;
            if(s[i]==c.substr(j,z)){
                if(j+z<k&&c[j+z]=='0') continue;
                for(int ii=j;ii<j+z;ii++) used[ii]=true;
                ans.push_back({j,i});
                break;
            }
        }
    }
    sort(all(ans));
    rep(i,n) cout << ans[i].second << " ";
    cout << endl;
}
0