답안 #89281

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89281 2018-12-11T09:28:36 Z turbat 아름다운 순열 (IZhO12_beauty) C++14
0 / 100
18 ms 3224 KB
#include <bits/stdc++.h>
using namespace std; 

int n, m, a[25], ans, cnt[25], cnt1[25];
long long dp[1<<20][21];
int main (){	
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		cnt[i] = __builtin_popcount(a[i]);
		m = a[i];
		while (m){
			if (m % 3 == 1) cnt1[i]++;
			m /= 3;
		}
	}
	for (int i = 0;i < n;i++) dp[1 << i][i] = 1;
	for (int i = 0;i < (1 << n);i++)
		for (int j = 0;j < n;j++)
			for (int o = 0;o < n;o++)
				if (!(i & 1<<o) && (cnt[j] == cnt[o] || cnt1[j] == cnt1[o]))
					dp[i|(1<<o)][o] += dp[i][j];
	for (int i = 0;i < n;i++) ans += dp[(1<<n) - 1][i];
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 480 KB Output is correct
3 Correct 2 ms 480 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 612 KB Output is correct
6 Correct 3 ms 660 KB Output is correct
7 Correct 3 ms 660 KB Output is correct
8 Correct 3 ms 788 KB Output is correct
9 Correct 3 ms 788 KB Output is correct
10 Correct 3 ms 788 KB Output is correct
11 Incorrect 18 ms 3224 KB Output isn't correct
12 Halted 0 ms 0 KB -