Submission #90113

# Submission time Handle Problem Language Result Execution time Memory
90113 2018-12-20T11:01:29 Z YottaByte Beautiful row (IZhO12_beauty) C++14
0 / 100
2 ms 256 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 20;
int n, ans;
vector < int > a;

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(vector < int > b)
{
	int c = 0;
	for(int i = 0; i < n - 1; i++)
	{
		if(__builtin_popcount(b[i]) == __builtin_popcount(b[i + 1]));
		else if(count(b[i], b[i + 1]));
		else return false;
	}
	return true;
}

void out(vector < int > tmp)
{
	for(int i = 0; i < tmp.size(); i++)
		cout << tmp[i] << " ";
	puts("");
}

void bt( vector < int > b, vector < int > u )
{
	if(b.size() == n)
	{
		if(check(b)) ans++;//, out(b);
		return;
	}
	
	for(int i = 0; i < n; i++)
	{
		if(!u[i])
		{
			u[i] = 1;
			b.push_back(a[i]);
			bt( b, u );
			b.pop_back();
			u[i] = 0;
		}
	}
}

main()
{
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		int x; cin >> x;
		a.push_back(x);
	}
	
	sort(a.begin() + 1, a.begin() + 1 + n);
	
	vector < int > t, t1;
	t1.clear();
	for(int i = 0; i < n; i++)
		t.push_back(0);
	
	bt( t1, t );
	cout << ans << endl;
}

Compilation message

beauty.cpp: In function 'bool check(std::vector<int>)':
beauty.cpp:29:6: warning: unused variable 'c' [-Wunused-variable]
  int c = 0;
      ^
beauty.cpp: In function 'void out(std::vector<int>)':
beauty.cpp:41:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < tmp.size(); i++)
                 ~~^~~~~~~~~~~~
beauty.cpp: In function 'void bt(std::vector<int>, std::vector<int>)':
beauty.cpp:48:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(b.size() == n)
     ~~~~~~~~~^~~~
beauty.cpp: At global scope:
beauty.cpp:67:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -