結果
| 問題 | No.1743 Permutation Code |
| ユーザー |
FplusFplusF
|
| 提出日時 | 2022-11-30 01:47:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,303 bytes |
| 記録 | |
| コンパイル時間 | 2,721 ms |
| コンパイル使用メモリ | 222,968 KB |
| 最終ジャッジ日時 | 2025-02-09 02:32:57 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 20 TLE * 10 |
コンパイルメッセージ
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;
| ^
ソースコード
#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;
}
FplusFplusF