답안 #670932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
670932 2022-12-11T11:08:43 Z dozer Swap (BOI16_swap) C++14
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define sp " "
#define endl "\n"
#define pii pair<int, int>
#define st first
#define nd second
#define N 100005
#define ai array<int, 3>

int arr[N], ans[N], n;

int f(int i, int j)
{
	int l = i * 2, r = i * 2 + 1;
	if (l > n) return j;
	if (r > n)
	{
		int t1 = j;
		int t2 = arr[l];
		int ans = min(t1, t2);
		return ans;
	}

	int t1 = j;
	int t2 = arr[l];
	int t3 = arr[r];

	int ans = min(t1, t2);
	ans = min(ans, t3);
	return ans;
}


void print(int i, int j)
{
	int l = i * 2, r = i * 2 + 1;
	//cout<<i<<sp<<j<<" : "<<l<<sp<<r<<sp<<arr[l]<<sp<<arr[r]<<endl;
	if (l > n) 
	{
		ans[i] = j;
		return;
	}
	if (r > n)
	{
		ai t1 = {j, f(l, arr[l]), 0};
		ai t2 = {arr[l], f(l, j), 0};
		if (t1 < t2)
		{
			ans[i] = j;
			print(l, arr[l]);
		}
		else
		{
			ans[i] = arr[l];
			print(l, j);
		}
		return;
	}

	ai t1 = {j, f(l, arr[l]), f(r, arr[r])};
	ai t2 = {arr[l], f(l, j), f(r, arr[r])};
	ai t3 = {arr[r], f(l, arr[l]), f(r, j)};
	ai t4 = {arr[r], f(l, j), f(r, arr[l])};
	ai res = min(t1, t2);
	res = min(res, t3);
	res = min(res, t4);
	if (res == t1)
	{
		ans[i] = j;
		print(l, arr[l]);
		print(r, arr[r]);
		return;
	}
	if (res == t2)
	{
		ans[i] = arr[l];
		print(l, j);
		print(r, arr[r]);
		return;
	}
	if (res == t3)
	{
		ans[i] = arr[r];
		print(l, arr[l]);
		print(r, j);
		return;
	}
	if (res == t4)
	{
		ans[i] = arr[r];
		print(l, j);
		print(r, arr[l]);
		return;
	}
}

int32_t main()
{
	fastio();

	cin>>n;
	for (int i = 1; i <= n; i++)
		cin>>arr[i];

	print(1, arr[1]);
	for (int i = 1; i <= n; i++) cout<<ans[i]<<sp;
	cout<<endl;

	cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -