//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
llo n;
llo it[200001];
llo ind[200001];
vector<llo> ans;
vector<pair<llo,llo>> kk;
void brute(llo ind){
if(ind*2>n){
vector<llo> ss;
for(llo i=1;i<=n;i++){
ss.pb(it[i]);
}
ans=min(ans,ss);
}
else if(ind*2==n){
llo x=it[ind];
llo y=it[ind*2];
llo xx=min(x,y);
if(xx==x){
brute(ind+1);
}
else{
swap(it[ind],it[ind*2]);
brute(ind+1);
}
it[ind]=x;
it[ind*2]=y;
}
else{
llo x=it[ind];
llo y=it[ind*2];
llo z=it[ind*2+1];
llo xx=min(x,y);
xx=min(xx,z);
if(xx==x){
brute(ind+1);
}
else if(xx==y){
swap(it[ind],it[ind*2]);
brute(ind+1);
}
else{
//if(x>y){
// kk.pb({y,z});
swap(it[ind],it[ind*2+1]);
brute(ind+1);
it[ind]=x;
it[ind*2]=y;
it[ind*2+1]=z;
/*}
else{*/
swap(it[ind],it[ind*2]);
swap(it[ind],it[ind*2+1]);
brute(ind+1);
//}
}
it[ind]=x;
it[ind*2]=y;
it[ind*2+1]=z;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
for(llo i=0;i<n;i++){
cin>>it[i+1];
ans.pb(it[i+1]);
}
brute(1);
//vector<llo> ans2=ans;
/*for(auto j:ans){
cout<<j<<",";
}
cout<<endl;*/
/*for(llo j=0;j<(1<<kk.size());j++){
vector<llo> cur=ans;
for(llo i=0;i<n;i++){
ind[ans[i]]=i;
}
for(llo i=0;i<kk.size();i++){
if((1LL<<i)&j){
swap(cur[ind[kk[i].a]],cur[ind[kk[i].b]]);
swap(ind[kk[i].a],ind[kk[i].b]);
}
else{
}
}
ans2=min(ans2,cur);
} */
/*for(auto j:kk){
cout<<j.a<<":"<<j.b<<endl;
}*/
for(auto j:ans){
cout<<j<<" ";
}
cout<<endl;
//cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
44 ms |
208 KB |
Output is correct |
10 |
Correct |
8 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
44 ms |
208 KB |
Output is correct |
10 |
Correct |
8 ms |
204 KB |
Output is correct |
11 |
Execution timed out |
1082 ms |
332 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
44 ms |
208 KB |
Output is correct |
10 |
Correct |
8 ms |
204 KB |
Output is correct |
11 |
Execution timed out |
1082 ms |
332 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
44 ms |
208 KB |
Output is correct |
10 |
Correct |
8 ms |
204 KB |
Output is correct |
11 |
Execution timed out |
1082 ms |
332 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |