Submission #992520

#TimeUsernameProblemLanguageResultExecution timeMemory
992520tch1cherinBeautiful row (IZhO12_beauty)C++17
100 / 100
700 ms205648 KiB
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N; cin >> N; vector<int> a(N); for (int &value : a) { cin >> value; } vector<int> b(N), t(N); for (int i = 0; i < N; i++) { int tmp = a[i]; while (tmp > 0) { b[i] += tmp % 2 == 1; tmp /= 2; } tmp = a[i]; while (tmp > 0) { t[i] += tmp % 3 == 1; tmp /= 3; } } vector<vector<long long>> dp(1 << N, vector<long long>(N)); for (int i = 0; i < N; i++) { dp[1 << i][i] = 1; } for (int mask = 0; mask < (1 << N); mask++) { for (int i = 0; i < N; i++) { if ((mask >> i) & 1) { for (int j = 0; j < N; j++) { if ((mask >> j) % 2 == 0 && (b[i] == b[j] || t[i] == t[j])) { dp[mask | (1 << j)][j] += dp[mask][i]; } } } } } long long answer = 0; for (int i = 0; i < N; i++) { answer += dp.back()[i]; } cout << answer << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...