結果
| 問題 |
No.1743 Permutation Code
|
| ユーザー |
Nachia
|
| 提出日時 | 2021-11-21 20:24:18 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,907 bytes |
| コンパイル時間 | 5,438 ms |
| コンパイル使用メモリ | 141,752 KB |
| 最終ジャッジ日時 | 2025-01-26 00:08:46 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 30 |
ソースコード
// oteage-no-mai
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
//#include <atcoder/modint>
using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(n); i++)
//using m32 = atcoder::static_modint<998'244'353>;
int msb_idx(u64 x){ return 63 - __builtin_clzll(x); }
int C_size_to_N(int C_size){
int n = 0;
int c_size_left = C_size;
while(c_size_left > 0){
n++;
c_size_left -= msb_idx(n) + 1;
}
if(c_size_left != 0) return -1;
return n;
}
string to_binstr(u64 n){
string res;
while(n){ res.push_back('0' + (n&1)); n>>=1; }
reverse(res.begin(), res.end());
return res;
}
u64 from_binstr(const string& s){
u64 res = 0;
for(char c : s) res = res * 2 + (c - '0');
return res;
}
string C;
int N;
vector<string> code;
vector<set<int>> candid;
vector<vector<int>> length_pos_code;
int main(){
cin >> C;
N = C_size_to_N(C.size());
//cerr << "N = " << N << endl;
code.resize(N);
for(int i=1; i<=N; i++) code[i-1] = to_binstr(i);
length_pos_code.assign(code.back().size()+1, vector<int>(C.size(), -1));
candid.resize(N);
for(int l=1; l<=code.back().size(); l++){
for(int p=0; p+l<=C.size(); p++){
if(C[p] == '0') continue;
if(C.size() != p+l) if(C[p+l] == '0') continue;
int v = from_binstr(C.substr(p,l));
if(v > N) continue;
length_pos_code[l][p] = v-1;
candid[v-1].insert(p);
}
}
vector<int> list_det;
for(int v=0; v<N; v++) if(candid[v].size() == 1) list_det.push_back(v);
for(int vi=0; vi<list_det.size(); vi++){
int v = list_det[vi];
int p = *candid[v].begin();
int l = code[v].size();
for(int nxl=1; nxl<=code.back().size(); nxl++){
for(int nxp=max<int>(0,p-nxl+1); nxp<=min<int>(C.size()-1,p+l-1); nxp++){
int nxv = length_pos_code[nxl][nxp];
if(nxv == -1) continue;
if(nxl == l && nxp == p) continue;
candid[nxv].erase(nxp);
length_pos_code[nxl][nxp] = -1;
if(candid[nxv].size() == 1) list_det.push_back(nxv);
}
}
}
//for(int i=0; i<N; i++){
// cerr << "candid " << (i+1) << " :";
// for(auto p : candid[i]) cerr << " " << p;
// cerr << "\n";
// cerr << flush;
//}
vector<pair<int,int>> ans;
for(int i=0; i<N; i++) ans.push_back({ *candid[i].begin(), i+1 });
sort(ans.begin(), ans.end());
for(int i=0; i<N; i++){
if(i) cout << " ";
cout << ans[i].second;
}
cout << "\n";
return 0;
}
struct ios_do_not_sync {
ios_do_not_sync() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
} ios_do_not_sync_instance;
Nachia