Submission #56191

# Submission time Handle Problem Language Result Execution time Memory
56191 2018-07-10T08:17:41 Z 정원준(#1583) Swap (BOI16_swap) C++11
0 / 100
3 ms 376 KB
#include <bits/stdc++.h>
#define L long long

using namespace std;

L n;
L a[200020];

L go(L val,L loc){
	if(loc*2>n) return loc;
	if(loc*2+1>n)
	{
		if(val>a[loc*2]) return loc;
		else return loc*2;
	}
	else
	{
		if(val<a[loc*2]&&val<a[loc*2+1]) return loc;
		if(val<a[loc*2]&&val>a[loc*2+1]) return go(val,loc*2+1);
		else return min(go(val,loc*2),go(val,loc*2+1));
	}
}

int main()
{
	scanf("%lld",&n);
	L i;
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(i=1;i<=n/2;i++)
	{
		if(i*2+1>n)
		{
			if(a[i]>a[i*2])
			{
				swap(a[i],a[i*2]);
			}
		}
		else
		{
			if(a[i*2]<a[i]&&a[i*2]<a[i*2+1])
			{
				swap(a[i],a[i*2]);
			}
			else if(a[i]<a[i*2]&&a[i]<a[i*2+1])
			{
				continue;
			}
			else
			{
				L temp=go(a[i],i*2)<go(a[i],i*2+1);
				if(temp==1) swap(a[i],a[i*2]);
				swap(a[i],a[i*2+1]); 
			}
		}
	}
	for(i=1;i<=n;i++)
	{
		printf("%lld ",a[i]);
	}
}

Compilation message

swap.cpp: In function 'int main()':
swap.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&n);
  ~~~~~^~~~~~~~~~~
swap.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&a[i]);
   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -