Submission #391958

# Submission time Handle Problem Language Result Execution time Memory
391958 2021-04-20T08:45:39 Z kshitij_sodani Swap (BOI16_swap) C++14
0 / 100
1 ms 204 KB
//#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];
vector<llo> ans;
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){
				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);
	for(auto j:ans){
		cout<<j<<" ";
	}
	cout<<endl;
	//cout<<ans<<endl;



 
 
	return 0;
}
 
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -