Submission #968945

# Submission time Handle Problem Language Result Execution time Memory
968945 2024-04-24T10:00:35 Z auslander Beautiful row (IZhO12_beauty) C++17
0 / 100
3000 ms 456 KB
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <iterator>
using namespace std;

typedef long long ll;
typedef unsigned usg;

#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define multi int t; cin>>t; while(t--) solve()
#define single solve(); return 0
#define ratdig(x) cout << fixed << setprecision(x);
#define xfixdig(x) cout << setprecision(x);
#define rev(x) reverse(x.begin(), x.end())
#define all(x) x.begin(), x.end()

void yn(bool b)
{
	if (b)
	{
		cout << "YES\n";
		return;
	}
	cout << "NO\n";
}

ll gcd(ll a, ll b) {
	if (a == 0)
		return b;
	if (b == 0)
		return a;
	return gcd(b % a, a);
}

ll lcm(ll a, ll b)
{
	return (a * b) / gcd(a, b);
}

string to2(ll a, ll n = -1)
{
	string r = "";
	for (ll i = 0; (1 << i) <= a; i++)
	{
		char c = (((1 << i) & a) != 0) + '0';
		r += c;
	}
	if (a == 0)
	{
		r = "0";
	}
	if (n != -1)
	{
		for (int i = 0; i < n - r.size(); i++)
			r += '0';
	}
	rev(r);

	return r;
}

ll b2(ll a)
{
	ll r = 0;
	while (a)
	{
		if (a % 2 == 1)
			r += a % 2;
		a /= 2;
	}

	return r;
}

ll b3(ll a, ll n = -1)
{
	ll r = 0;
	while (a)
	{
		if (a % 3 == 1)
			r += a % 3;
		a /= 3;
	}

	return r;
	
	return r;
}

ll binpow(ll a, ll b, ll mod = -1)
{
	ll ans = 1;
	while (b)
	{
		if ((b & 1) == 1)
		{
			ans *= a;
			if (mod != -1)
				ans %= mod;
		}
		b >>= 1;
		a *= a;
		if (mod != -1)
			a %= mod;
	}
	return ans;
}
ll arr[25], a2[25], a3[25];
ll a[25];

void solve()
{
	int m, n, i, j, k;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> arr[i];
		a[i] = i;
		a2[i] = b2(arr[i]);
		a3[i] = b3(arr[i]);
	}
	ll res = 0;
	do {
		for (i = 1; i < n; i++)
		{
			if (a2[a[i]] != a2[a[i - 1]] && a3[a[i]] != a3[a[i - 1]])
			{
				res--;
				break;
			}
		}
		res++;
	} while (next_permutation(a, a + n));
	cout << res;
 }

int main()
{
	speed;
	single;
	multi;
	return 0;
} 

Compilation message

beauty.cpp: In function 'std::string to2(ll, ll)':
beauty.cpp:63:21: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   63 |   for (int i = 0; i < n - r.size(); i++)
      |                   ~~^~~~~~~~~~~~~~
beauty.cpp: In function 'void solve()':
beauty.cpp:122:6: warning: unused variable 'm' [-Wunused-variable]
  122 |  int m, n, i, j, k;
      |      ^
beauty.cpp:122:15: warning: unused variable 'j' [-Wunused-variable]
  122 |  int m, n, i, j, k;
      |               ^
beauty.cpp:122:18: warning: unused variable 'k' [-Wunused-variable]
  122 |  int m, n, i, j, k;
      |                  ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 19 ms 348 KB Output is correct
7 Correct 15 ms 456 KB Output is correct
8 Correct 37 ms 348 KB Output is correct
9 Correct 17 ms 344 KB Output is correct
10 Correct 36 ms 348 KB Output is correct
11 Execution timed out 3078 ms 348 KB Time limit exceeded
12 Halted 0 ms 0 KB -