답안 #41133

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41133 2018-02-13T04:55:55 Z wzy 아름다운 순열 (IZhO12_beauty) C++14
0 / 100
124 ms 172664 KB
#include <bits/stdc++.h>
using namespace std;
#define F first
#define pb push_back
#define S second
#define pii pair<int,int>
#define int long long
int n;
vector<int> v;
vector<int> adj[30];
int dp[21][1LL<<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);
}


int solve(int i , int mask){
	if(dp[i][mask] != -1) return dp[i][mask];
	int maxxi = 1<<n;
	maxxi--;
	if(mask == maxxi) return 1;
	dp[i][mask] = 0;
	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] += (mask == 1<<i ? solve(i+1 , 1<<(i+1)) : 0);
}

int32_t main(){
	cin>>n;
	v.resize(n);
	for(int i = 0 ; i < n ;i++) cin>>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);
			}
		}
	}
	memset(dp, - 1 , sizeof dp);
	int ans = 0;
	ans+= solve(0 , 1<<0);
	cout<<ans<<endl;
}

Compilation message

beauty.cpp: In function 'long long int solve(long long int, long long int)':
beauty.cpp:34:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 0 ; j < adj[i].size() ; j++){
                    ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 124 ms 172664 KB Output isn't correct
2 Halted 0 ms 0 KB -