Submission #391945

# Submission time Handle Problem Language Result Execution time Memory
391945 2021-04-20T08:32:37 Z kshitij_sodani Swap (BOI16_swap) C++14
21 / 100
1000 ms 332 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{
			swap(it[ind],it[ind*2+1]);
			brute(ind+1);
			it[ind]=x;
			it[ind*2]=y;
			it[ind*2+1]=z;
			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 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 45 ms 204 KB Output is correct
10 Correct 9 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 45 ms 204 KB Output is correct
10 Correct 9 ms 324 KB Output is correct
11 Execution timed out 1075 ms 332 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 45 ms 204 KB Output is correct
10 Correct 9 ms 324 KB Output is correct
11 Execution timed out 1075 ms 332 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 45 ms 204 KB Output is correct
10 Correct 9 ms 324 KB Output is correct
11 Execution timed out 1075 ms 332 KB Time limit exceeded
12 Halted 0 ms 0 KB -