Submission #328824

#TimeUsernameProblemLanguageResultExecution timeMemory
328824gustasonBeautiful row (IZhO12_beauty)C++14
0 / 100
1 ms364 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; pair<int, int> ones[21]; int n; int ternary_ones(int x) { int s = 0; while(x > 0) { if (x % 3 == 1) s++; x /= 3; } return s; } ll cnt = 0; void go(int id, bool used[], pair<int, int> last) { if (id == n) { cnt++; return; } for(int i = 0; i < n; i++) { if (used[i]) continue; if (ones[i].first == last.first || ones[i].second == last.second) { used[i] = true; go(id + 1, used, ones[i]); used[i] = false; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for(int i = 0; i < n; i++) { int x; cin >> x; ones[i].first = __builtin_popcount(x); ones[i].second = ternary_ones(x); cout << x << " " << ones[i].first << " " << ones[i].second << "\n"; } // for(int i = 0; i < n; i++) { // cout << ones[i].first << " " << ones[i].second; // } bool used[n]; fill(used, used + n, false); for(int i = 0; i < n; i++) { used[i] = true; go(1, used, ones[i]); used[i] = false; } cout << cnt; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...