Submission #106203

#TimeUsernameProblemLanguageResultExecution timeMemory
106203HideoBeautiful row (IZhO12_beauty)C++14
0 / 100
15 ms1664 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mk make_pair #define fr first #define sc second #define vi vector < int > #define vl vector < ll > #define pi pair < int, int > #define pii pair < int, pi > #define vii vector < pi > const int N = 1e5 + 7; const int INF = 1e9 + 7; int dp[(1 << 20)][20]; int b[20], t[20]; int n, ans; int bin (int x, int c = 0){ if (x % 2 == 1) c++; if (!x) return c; bin(x / 2, c); } int ter (int x, int c = 0){ if (x % 3 == 1) c++; if (!x) return c; ter(x / 3, c); } main(){ cin >> n; for (int i = 0; i < n; i++){ int a; cin >> a; b[i] = bin(a); t[i] = ter(a); } for (int i = 0; i < n; i++) dp[(1 << i)][i] = 1; for (int val = 2; val <= n; val++){ for (int mask = 1; mask < (1 << n); mask++){ int cnt = 0; for (int sub = 0; sub < n; sub++){ if (mask & (1 << sub)) cnt++; } if (cnt != val) continue; for (int sub = 0; sub < n; sub++){ if (mask & (1 << sub)){ int submask = (mask ^ (1 << sub)); for (int last = 0; last < n; last++){ if (submask & (1 << last) && (b[last] == b[sub] || t[last] == t[sub])){ dp[mask][sub] += dp[submask][last]; } } } } if (val == n){ for (int last = 0; last < n; last++){ ans += dp[mask][last]; } cout << ans; return 0; } } } }

Compilation message (stderr)

beauty.cpp:38:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
beauty.cpp: In function 'int bin(int, int)':
beauty.cpp:28:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
beauty.cpp: In function 'int ter(int, int)':
beauty.cpp:36:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...