# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
742405 | 2023-05-16T08:33:29 Z | anha3k25cvp | Beautiful row (IZhO12_beauty) | C++14 | 552 ms | 205584 KB |
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define dl double #define st first #define nd second #define II pair <int, int> using namespace std; const int N = 5 + 1e5; const int inf = 7 + 1e9; vector <int> a; vector <vector <int>> cnt, b; vector <vector <ll>> f; int cal2(int x) { int ans = 0; while (x > 0) { if (x % 2 == 1) ans ++; x /= 2; } return ans; } int cal3(int x) { int ans = 0; while (x > 0) { if (x % 3 == 1) ans ++; x /= 3; } return ans; } int main() { #define TASKNAME "beauty" ios_base::sync_with_stdio (0); cin.tie (0); if ( fopen( TASKNAME".inp", "r" ) ) { freopen (TASKNAME".inp", "r", stdin); freopen (TASKNAME".out", "w", stdout); } int n; cin >> n; a.assign(n, 0); for (int i = 0; i < n; i ++) cin >> a[i]; cnt.assign(n, vector <int> (4, 0)); for (int i = 0; i < n; i ++) { cnt[i][2] = cal2(a[i]); cnt[i][3] = cal3(a[i]); } b.assign(n, vector <int> (n, 0)); for (int i = 0; i < n; i ++) for (int j = i + 1; j < n; j ++) if (cnt[i][2] == cnt[j][2] || cnt[i][3] == cnt[j][3]) { b[i][j] = 1; b[j][i] = 1; } f.assign(1 << n, vector <ll> (n, 0)); for (int i = 0; i < n; i ++) f[1 << i][i] = 1; for (int mask = 1; mask < (1 << n); mask ++) for (int si = mask; si > 0; si ^= si & -si) { int i = __builtin_ctz(si & -si); for (int sj = ((1 << n) - 1) ^ mask; sj > 0; sj ^= sj & -sj) { int j = __builtin_ctz(sj & -sj); if (b[i][j]) f[mask | 1 << j][j] += f[mask][i]; } } ll ans = 0; for (int i = 0; i < n; i ++) ans += f[(1 << n) - 1][i]; cout << ans; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 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 | 316 KB | Output is correct |
8 | Correct | 1 ms | 448 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 | 2752 KB | Output is correct |
12 | Correct | 5 ms | 2772 KB | Output is correct |
13 | Correct | 21 ms | 11092 KB | Output is correct |
14 | Correct | 114 ms | 47496 KB | Output is correct |
15 | Correct | 107 ms | 47488 KB | Output is correct |
16 | Correct | 134 ms | 47400 KB | Output is correct |
17 | Correct | 120 ms | 47496 KB | Output is correct |
18 | Correct | 143 ms | 47432 KB | Output is correct |
19 | Correct | 552 ms | 205584 KB | Output is correct |
20 | Correct | 545 ms | 205520 KB | Output is correct |