# | 제출 시각UTC-0 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
89282 | turbat | 아름다운 순열 (IZhO12_beauty) | C++14 | 1792 ms | 205924 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
long long n, m, a[25], dp[1<<21][25], ans, cnt[25], cnt1[25];
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;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |