結果
| 問題 |
No.1743 Permutation Code
|
| ユーザー |
FplusFplusF
|
| 提出日時 | 2022-11-29 22:24:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,680 bytes |
| コンパイル時間 | 2,245 ms |
| コンパイル使用メモリ | 205,884 KB |
| 最終ジャッジ日時 | 2025-02-09 02:26:22 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 TLE * 24 |
ソースコード
#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);
}
FplusFplusF