Submission #382240

# Submission time Handle Problem Language Result Execution time Memory
382240 2021-03-26T19:30:02 Z ritul_kr_singh Beautiful row (IZhO12_beauty) C++17
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << " " <<
#define nl << "\n"

signed main(){
    cin.tie(0)->sync_with_stdio(0);
    int n, x, y; cin >> n;
    int b2[n], b3[n];
    for(int i=0; i<n; ++i){
    	b2[i] = b3[i] = 0;
    	cin >> x;
    	y = x;
    	while(y) b2[i] += (y % 2)==1, y /= 2;
    	while(x) b3[i] += (x % 3)==1, x /= 3;
    }

    bool d[n][n];
    for(int i=0; i<n; ++i)
    	for(int j=0; j<n; ++j)
    		d[i][j] = b2[i]==b2[j] or b2[i]==b3[j] or b3[i]==b2[j] or b3[i]==b3[j];

    int ans[1<<n][n];
    for(int i=0; i<(1<<n); ++i){
    	for(int j=0; j<n; ++j){
    		ans[i][j] = 0;
    		if(i==(1<<j)) ans[i][j] = 1;
    	}
    	for(int j=0; j<n; ++j){
    		for(int k=j+1; k<n; ++k){
    			if(!(i&(1<<j)) or !(i&(1<<k))) continue;
    			if(d[j][k]){
    				ans[i][j] += ans[i^(1<<j)][k];
    				ans[i][k] += ans[i^(1<<k)][j];
    			}
    		}
    	}
    }
    cout << accumulate(ans[(1<<n)-1], ans[(1<<n)-1]+n, 0LL);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -