Submission #913823

#TimeUsernameProblemLanguageResultExecution timeMemory
913823cotBeautiful row (IZhO12_beauty)C++14
0 / 100
3038 ms600 KiB
#include <iostream> #include <algorithm> #include <map> #include <array> #define f first #define s second #define pii pair <int, int> #define pb push_back using namespace std; const int N = 50 + 5; int n, a[N], b[N], p[N], ans, good[N][N]; int ones3(int x) { int cnt = 0; while (x > 0) { if (x % 3 == 1) cnt++; x /= 3; } return cnt; } int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; p[i] = i; } for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if (__builtin_popcountll(a[i]) == __builtin_popcountll(a[j]) || ones3(a[i]) == ones3(a[j])) { good[i][j] = good[j][i] = 1; continue; } } } do { for (int i = 1; i <= n; i++) { b[i] = a[p[i]]; } int bad = 0; for (int i = 1; i < n; i++) { if (!good[p[i]][p[i + 1]]) bad = 1; } if (!bad) ans++; } while(next_permutation(p + 1, p + n + 1)); cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...