Submission #90109

# Submission time Handle Problem Language Result Execution time Memory
90109 2018-12-20T10:01:48 Z YottaByte Beautiful row (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()
      ^
# Verdict Execution time Memory 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 -