답안 #90109

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
90109 2018-12-20T10:01:48 Z YottaByte 아름다운 순열 (IZhO12_beauty) C++14
0 / 100
303 ms 704 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 20;
int a[N + 1], n, ans;

inline bool count(int a, int b)
{
	int resa, resb;
	resa = resb = 0;
	
	while(a)
	{
		resa += (a % 3 == 1);
		a /= 3;
	}
	
	while(b)
	{
		resb += (b % 3 == 1);
		b /= 3;
	}
	return (resa == resb);
}

inline bool check()
{
	int c = 0;
	for(int i = 1; i < n; i++)
	{
		if(__builtin_popcount(a[i]) == __builtin_popcount(a[i + 1])) c++;
		else if(count(a[i], a[i + 1])) c++;
		else return false;
	}
	return true;
}

void out()
{
	for(int i = 1; i <= n; i++)
	{
		cout << a[i] << " ";
	}
}

main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	
	sort(a + 1, a + 1 + n);
	
	do
	{
		if(check())
			ans++;
	} while(next_permutation(a + 1, a + 1 + n));
	
	cout << ans << endl;
}

Compilation message

beauty.cpp:46:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 576 KB Output is correct
4 Correct 2 ms 576 KB Output is correct
5 Correct 2 ms 576 KB Output is correct
6 Correct 236 ms 704 KB Output is correct
7 Correct 184 ms 704 KB Output is correct
8 Correct 303 ms 704 KB Output is correct
9 Incorrect 99 ms 704 KB Output isn't correct
10 Halted 0 ms 0 KB -