Submission #90103

#TimeUsernameProblemLanguageResultExecution timeMemory
90103Aydarov03Beautiful row (IZhO12_beauty)C++14
0 / 100
3020 ms600 KiB
#include <bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
int a[30];
int st[30];
bool used[30];
int n , ans;
map <int,int> bin;
map <int,int> ter;



void rec( int k )
{
	if( k == n + 1 )
	{
		for(int i = 1; i < n; i++)
			if( ter[ st[i] ] != ter[ st[i+1] ] && bin[ st[i] ] != bin[ st[i+1] ])return;
		
		ans++;
		return;
		
	}
	
	for(int i = 1; i <= n; i++)
	{
		if( !used[i] )
		{
			st[k] = a[i];
			used[ i ] = true;
			rec( k + 1 );
			used[ i ] = false;
		}
		
		
	}
}

void to_bin( int a )
{
	int one = 0;
	int A = a;
	
	while( a > 0 )
	{
		one += ( a % 2 == 1);
		a /= 2;
	}
	
	bin[ A ] = one;
}

void to_ter( int a )
{
	int one = 0;
	int A = a;
	while( a > 0 )
	{
		one += ( a % 3 == 1);
		a /= 3;
	}
	
	ter[ A ] = one;
}





main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)cin >> a[i];
	
	for(int i = 1; i <= n; i++)
	{
		to_bin( a[i] );
		to_ter( a[i] );
	}
	
	
	rec( 1 );
	
	cout << ans;
	
}

Compilation message (stderr)

beauty.cpp:71:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...