제출 #499943

#제출 시각아이디문제언어결과실행 시간메모리
499943ac2hu아름다운 순열 (IZhO12_beauty)C++14
0 / 100
3099 ms288 KiB
#include<bits/stdc++.h> using namespace std; bool used[21]; int t2[21],t3[21]; int n; long long int ans = 0; void rec(int last, int num){ if(num == n){ used[last] = false; ans ++; } else{ for(int i = 0;i<n;i++){ if(!used[i] && (t2[last] == t2[i] || t3[last] == t3[i])){ used[i] = true; rec(i,num + 1); used[i] = false; } } used[last] = false; } } void solve(){ cin >> n; vector<int> a(n); for(int i = 0;i<n;i++)cin >> a[i]; for(int i = 0;i<n;i++){ t2[i] = 0; t3[i] = 0; int temp =a[i]; while(temp != 0){ if(temp%2 == 1) t2[i]++; temp /= 2; } temp = a[i]; while(temp != 0){ if(temp%3 == 1) t3[i]++; temp /= 3; } // cout << t2[i] << " " << t3[i] << "\n"; } for(int i = 0;i<n;i++){ used[i] = true; rec(i, 1); used[i] = false; } cout << ans << "\n"; } signed main(){ iostream::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr); int T = 1; //cin >> T; while(T--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...