#include <bits/stdc++.h>
using namespace std;
#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;
int main()
{
int n;
scd(n);
vi vec(n);
vi cnt2(n), cnt3(n);
frange(i, n)
{
int a;
scd(a);
vec[i] = a;
int v1 = a;
int v2 = a;
while (v1 > 0)
{
if (v1 % 2 == 1)
cnt2[i]++;
v1 /= 2;
}
while (v2 > 0)
{
if (v2 % 3 == 1)
cnt3[i]++;
v2 /= 3;
}
}
vector<vll> dp(1 << n, vll(n));
frange(i, n)
{
dp[1 << i][i] = 1;
}
frange(i, 1 << n)
{
frange(j, n)
{
if (i & (1 << j))
{
frange(k, n)
{
if (cnt2[j] == cnt2[k] || cnt3[k] == cnt3[j])
{
dp[i][j] += dp[i ^ (1 << j)][k];
// printf("%d %d %lld\n", k, j, dp[i][j]);
}
}
}
}
}
lli tot = 0;
frange(i, n)
{
tot += dp[(1 << n) - 1][i];
}
// lli fac = 1;
// forr(i, 1, n + 1) fac *= i;
printf("%lld", tot);
}
Compilation message
beauty.cpp: In function 'int main()':
beauty.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
beauty.cpp:30:5: note: in expansion of macro 'scd'
30 | scd(n);
| ^~~
beauty.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
beauty.cpp:37:9: note: in expansion of macro 'scd'
37 | scd(a);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
2720 KB |
Output is correct |
12 |
Correct |
4 ms |
2644 KB |
Output is correct |
13 |
Correct |
20 ms |
11088 KB |
Output is correct |
14 |
Correct |
90 ms |
47380 KB |
Output is correct |
15 |
Correct |
100 ms |
47492 KB |
Output is correct |
16 |
Correct |
93 ms |
47472 KB |
Output is correct |
17 |
Correct |
102 ms |
47488 KB |
Output is correct |
18 |
Correct |
95 ms |
47492 KB |
Output is correct |
19 |
Correct |
441 ms |
205480 KB |
Output is correct |
20 |
Correct |
444 ms |
205384 KB |
Output is correct |