Submission #41135

#TimeUsernameProblemLanguageResultExecution timeMemory
41135wzyBeautiful row (IZhO12_beauty)C++14
0 / 100
3093 ms145236 KiB
#include <stdio.h>
#include <vector>
using namespace std;
#define F first
#define pb push_back
#define S second
#define pii pair<int,int>
int n;
vector<int> v;
vector<int> adj[30];
long long dp[21][1<<20];
bool vis[21][1<<20];
pair<int,int> f(int x){
	int a1 = 0 , a2 = 0;
	int z =x;
	while(z > 0){
		if(z%2 == 1) a1++;
		z/= 2;
	}
	z = x;
	while(z > 0){
		if(z%3 == 1) a2++;
		z/=3;
	}
	return pair<int,int>(a1, a2);
}


long long solve(int i , int mask){
	if(vis[i][mask]) return dp[i][mask];
	vis[i][mask] = true;
	int maxxi = 1<<n;
	maxxi--;
	if(mask == maxxi) return dp[i][mask] = 1;
	for(int j = 0 ; j < adj[i].size() ; j++){
		int v = adj[i][j];
		if(mask & 1<<v) continue;
		dp[i][mask] += solve(v , 1<<v | mask);
	}
	return dp[i][mask];
}

int main(){
	scanf("%d" , &n);
	v.resize(n);
	for(int i = 0 ; i < n ;i++) scanf("%d" , &v[i]);
	for(int i = 0 ; i <n; i++){
		for(int j = i + 1 ; j < n;j++){
			if(f(v[i]).F == f(v[j]).F || f(v[i]).S ==f(v[j]).S){
				adj[i].pb(j);
				adj[j].pb(i);
			}
		}
	}
	long long ans = 0;
	for(int i = 0 ; i < n ; i++){
		ans+= solve(i , 1<<i);
	}
	printf("%lld\n" , ans);
}

Compilation message (stderr)

beauty.cpp: In function 'long long int solve(int, int)':
beauty.cpp:35:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 0 ; j < adj[i].size() ; j++){
                    ^
beauty.cpp: In function 'int main()':
beauty.cpp:44:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d" , &n);
                  ^
beauty.cpp:46:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0 ; i < n ;i++) scanf("%d" , &v[i]);
                                                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...