Submission #90110

# Submission time Handle Problem Language Result Execution time Memory
90110 2018-12-20T10:28:31 Z Aydarov03 Beautiful row (IZhO12_beauty) C++14
0 / 100
3000 ms 620 KB
//16272
#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 )
	{
		ans++;
		return;
		
	}
			
			
	for(int i = 1; i <= n; i++)
	{
		if( k == 1 || ( !used[i] && ( ter[a[i]] == ter[st[k-1]] || bin[a[i]] == bin[st[k-1]] ) )  )
		{	
			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

beauty.cpp:73:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 8 ms 484 KB Output is correct
7 Correct 2 ms 484 KB Output is correct
8 Correct 537 ms 620 KB Output is correct
9 Correct 5 ms 620 KB Output is correct
10 Correct 241 ms 620 KB Output is correct
11 Execution timed out 3032 ms 620 KB Time limit exceeded
12 Halted 0 ms 0 KB -