Submission #391993

# Submission time Handle Problem Language Result Execution time Memory
391993 2021-04-20T09:36:00 Z MahdiBahramian Swap (BOI16_swap) C++11
0 / 100
3 ms 4940 KB
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int Max = 2e5 + 10;

int A[Max] , P[Max]; vector<int> N[Max];
int main()
{
	int n; cin >> n;
	for(int i = 1 ; i <= n ; i++)
		cin >> A[i] , P[A[i]] = i , N[A[i]].pb(A[i / 2]) , N[A[i / 2]].pb(A[i]);

	for(int x = 1 ; x <= n ; x++)
	{
		int mnpos = P[x];
		for(int u : N[x]) if(u > x) mnpos = min(mnpos , P[u]);
		
		if(mnpos < P[x])
		{
			int i = P[x] , j = mnpos;
			swap(A[i] , A[j]);
			swap(P[A[i]] , P[A[j]]);
		}
	}
	for(int i = 1 ; i <= n ; i++) cout << A[i] << ' ';
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -