# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
499943 | ac2hu | Beautiful row (IZhO12_beauty) | C++14 | 3099 ms | 288 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |