結果

問題 No.1743 Permutation Code
ユーザー FplusFplusFFplusFplusF
提出日時 2022-11-30 01:47:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,303 bytes
コンパイル時間 2,725 ms
コンパイル使用メモリ 224,660 KB
実行使用メモリ 79,260 KB
最終ジャッジ日時 2024-04-16 13:41:56
合計ジャッジ時間 24,368 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
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 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:72:30: warning: 'l' may be used uninitialized [-Wmaybe-uninitialized]
   72 |                 for(int j=l;j<r;j++) vt[j].resize(0);
      |                             ~^~
main.cpp:60:19: note: 'l' was declared here
   60 |             int x,l,r;
      |                   ^
main.cpp:72:30: warning: 'r' may be used uninitialized [-Wmaybe-uninitialized]
   72 |                 for(int j=l;j<r;j++) vt[j].resize(0);
      |                             ~^~
main.cpp:60:21: note: 'r' was declared here
   60 |             int x,l,r;
      |                     ^

ソースコード

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<vector<tuple<int,int,int>>> vt(k);
    set<int> st;
    for(int i=1;i<=n;i++){
        st.insert(i);
        rep(j,k-s[i].size()+1){
            if(s[i]==c.substr(j,s[i].size())){
                for(int ii=j;ii<j+(int)s[i].size();ii++){
                    vt[ii].emplace_back(i,j,j+s[i].size());
                }
            }
        }
    }
    vector<pair<int,int>> ans;
    while(true){
        bool t=false;
        rep(i,k){
            if(vt[i].size()==0) continue;
            set<int> kind;
            int x,l,r;
            for(auto &[aa,bb,cc]:vt[i]){
                if(!st.count(aa)) continue;
                kind.insert(aa);
                x=aa;
                l=bb;
                r=cc;
            }
            if(kind.size()==1){
                t=true;
                ans.emplace_back(i,x);
                st.erase(x);
                for(int j=l;j<r;j++) vt[j].resize(0);
                break;
            }
        }
        if(!t) break;
    }
    vector<int> last;
    for(auto &i:st) last.push_back(i);
    sort(all(last));
    reverse(all(last));
    int p=0;
    rep(i,k){
        if((int)last.size()==0||(int)ans.size()==n) break;
        if(vt[i].size()==0) continue;
        set<int> kind;
        for(auto &[x,l,r]:vt[i]){
            if(x==p){
                ans.emplace_back(i,x);
                for(int j=l;j<r;j++) vt[j].resize(0);
                p++;
                break;
            }
        }
    }
    sort(all(ans));
    rep(i,n) cout << ans[i].second << " ";
    cout << endl;
}
0