답안 #499957

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
499957 2021-12-30T06:21:47 Z ac2hu 아름다운 순열 (IZhO12_beauty) C++14
0 / 100
6 ms 1100 KB
#include<bits/stdc++.h>
using namespace std;
void solve(){
	int n;cin >> n;
	vector<int> t2(n),t3(n);
	for(int i = 0;i<n;i++){
		int a;cin >> a;
		t2[i] = 0;
		t3[i] = 0;
		int temp  =a;
		while(temp != 0){
			if(temp%2 == 1)
				t2[i]++;
			temp /= 2;
		}
		temp = a;
		while(temp != 0){
			if(temp%3 == 1)
				t3[i]++;
			temp /= 3;
		}
	}
	int dp[n][(1 << n)];
	for(int j = 1;j<(1 << n);j++){
		for(int i = 0;i<n;i++){
			dp[i][j] = 0;
		}
	}
	for(int i = 0;i<n;i++)
		dp[i][(1 << i)] = 1;
	for(int j = 1;j<(1 << n);j++){
		vector<int> selected;
		for(int i = 0;i<n;i++){
			if(j&(1 << i))
				selected.push_back(i);
		}
		for(int e : selected){
			for(int f : selected){
				if(e != f){
					if(t2[e] == t2[f] || t3[e] == t3[f]){
						dp[e][j] += dp[f][j^(1 << e)];
					}
				}
			}
		}
	}
	int ans = 0;
	for(int i = 0;i<n;i++)
		ans += dp[i][(1 << n) - 1];
	cout << ans << "\n";
}
signed main(){
	iostream::sync_with_stdio(false);
	cin.tie(nullptr);cout.tie(nullptr);
	int T = 1;
	//cin >> T;
	while(T--){
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Incorrect 6 ms 1100 KB Output isn't correct
12 Halted 0 ms 0 KB -