Submission #1008953

# Submission time Handle Problem Language Result Execution time Memory
1008953 2024-06-27T06:55:00 Z ArgoCahaya Swap (BOI16_swap) C++14
0 / 100
1000 ms 600 KB
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define pll pair<long long, long long>
#define loop(i,n) for(int i=1;i<=n;i++)
#define loop0(i,n) for(int i=0;i<n;i++)
using namespace std;

//pbds template
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//template <class T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

void solve(){
	ll n;
	cin >> n;
	ll arr[n+5];
	for(int i=1;i<=n;i++){
		cin >> arr[i];
	}
	priority_queue<ll,vector<ll>,greater<ll>> pq[n+5];
	for(int i=1;i<=n/2;i++){
		pq[i].push(arr[i]);
		pq[i].push(arr[i*2]);
		pq[i*2].push(arr[i]);
		pq[i*2].push(arr[i*2]);
		if(i*2+1<=n){
			pq[i*2+1].push(arr[i]);
			pq[i*2+1].push(arr[i*2]);
			pq[i*2+1].push(arr[i*2+1]);
			pq[i*2].push(arr[i*2+1]);
			pq[i].push(arr[i*2+1]);
		}
	}
	ll ans[n+5] = {0};
	ll occ[n+5] = {0};
	for(int i=1;i<=n;i++){
		while(occ[pq[i].top()]==1){
			pq[i].pop();
		}
		cout << pq[i].top() << ' ';
		occ[pq[i].top()] = 1;
	}
	cout << endl;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc = 1;
//	cin >> tc;
	while(tc--){
	   solve();
	}
}

Compilation message

swap.cpp: In function 'void solve()':
swap.cpp:41:5: warning: unused variable 'ans' [-Wunused-variable]
   41 |  ll ans[n+5] = {0};
      |     ^~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1041 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1041 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1041 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1041 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1041 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -