Submission #1111842

#TimeUsernameProblemLanguageResultExecution timeMemory
1111842TsaganaBeautiful row (IZhO12_beauty)C++14
0 / 100
9 ms2516 KiB
#include<bits/stdc++.h> #define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie(); #define all(x) x.begin(), x.end() #define lnl long long #define pq priority_queue #define eb emplace_back #define lb lower_bound #define ub upper_bound #define pb push_back #define pp pop_back #define F first #define S second using namespace std; int l[25]; int s[25][5]; int dp[2000000][25]; int to2(int x) { int ans = 0; while (x) {if (x%2 == 1) ans++; x /= 2;} return ans; } int to3(int x) { int ans = 0; while (x) {if (x%3 == 1) ans++; x /= 3;} return ans; } void solve () { l[0] = 1; for (int i = 1; i <= 20; i++) l[i] = l[i-1]*2; int n; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; s[i][2] = to2(x); s[i][3] = to3(x); } for (int i = 0; i < n; i++) dp[l[i]][i] = 1; for (int i = 0; i < l[n]; i++) for (int j = 0; j < n; j++) for (int k = 0; k < n; k++) { if (i & l[k]) continue ; if (s[j][2] == s[k][2] || s[j][3] == s[k][3]) { dp[i|l[k]][k] += dp[i][j]; } } int ans = 0; for (int i = 0; i < n; i++) ans += dp[l[n]-1][i]; cout << ans; } int main() {IOS solve(); return 0;}
#Verdict Execution timeMemoryGrader output
Fetching results...