이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
ll mx, K;
vector<int>Ans;
void solve(){
vector<int>AAns;
bitset<1000>a=K;
int group=0;
for(int i=0;i<=64;i++){
if(a[i]){
group++;
for(int j=0;j<i;j++)
AAns.push_back(j);
}
}
vector<int>Old=AAns;
int n=AAns.size(), cur=0;
for(int i=n-1;i>=0;i--){
if(!Old[i]){
int ind=i;
while(true){
AAns[ind]=cur++;
if(ind<n-1 && Old[ind+1])
ind++;
else
break;
}
}
}
group--;
for(int i=0;i<AAns.size();i++)
AAns[i]+=mx;
mx+=cur;
for(int i=0;i<Ans.size();i++){
AAns.push_back(Ans[i]);
}
Ans=AAns;
if(group>1){
K=group+1;
solve();
}
else if(group){
int s=mx;
for(int i=0;i<Ans.size();i++){
swap(Ans[i], s);
}
Ans.push_back(s);
}
}
vector<int> construct_permutation(ll k){
K=k;
mx=0;
Ans.clear();
solve();
vector<int>parts;
int cur=0;
for(int i=0;i<Ans.size();i++){
cur++;
if(i==Ans.size()-1 || Ans[i+1]<Ans[i])
parts.push_back(cur), cur=0;
}
K=0;
sort(all(parts));
int now=1, Mx=100, ind=0;
Ans.clear();
int last=-1;
for(int i=0;ind<parts.size();i++){
if(now==parts[ind]){
ind++;
Ans.push_back(cur++);
}
else{
Ans.push_back(Mx--);
if(last!=-1){
K+=(i-last)*(last+1!=i);
}
last=i;
now++;
}
}
mx=0;
int mn=100;
for(int i=Ans.size()-1;i>=0;i--){
if(Ans[i]>=cur){
if(mn==100)
mn=Ans[i];
Ans[i]-=mn-cur;
}
mx=max((int)mx, Ans[i]+1);
}
reverse(all(Ans));
if(K)
solve();
return Ans;
}
컴파일 시 표준 에러 (stderr) 메시지
perm.cpp: In function 'void solve()':
perm.cpp:37:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i=0;i<AAns.size();i++)
| ~^~~~~~~~~~~~
perm.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int i=0;i<Ans.size();i++){
| ~^~~~~~~~~~~
perm.cpp:50:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i=0;i<Ans.size();i++){
| ~^~~~~~~~~~~
perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:64:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i=0;i<Ans.size();i++){
| ~^~~~~~~~~~~
perm.cpp:66:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | if(i==Ans.size()-1 || Ans[i+1]<Ans[i])
| ~^~~~~~~~~~~~~~
perm.cpp:74:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int i=0;ind<parts.size();i++){
| ~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |