| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1037018 | pera | 아름다운 순열 (IZhO12_beauty) | C++17 | 628 ms | 172892 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int N = 20 , LOG = 30;
int n;
vector<int> a(N);
vector<vector<long long>> dp(N , vector<long long>(1 << N));
vector<vector<int>> v(N);
int t_o_c(int x){
int cnt = 0;
while(x > 0){
cnt += (x % 3 == 1);
x /= 3;
}
return cnt;
}
int main(){
cin >> n;
for(int i = 0;i < n;i ++){
cin >> a[i];
}
for(int x = 0;x < n;x ++){
for(int y = 0;y < n;y ++){
if(x != y && (__builtin_popcount(a[x]) == __builtin_popcount(a[y]) || t_o_c(a[x]) == t_o_c(a[y]))){
v[x].push_back(y);
}
}
dp[x][1 << x] = 1LL;
}
for(int mask = 0;mask < (1 << n);mask ++){
for(int x = 0;x < n;x ++){
if(mask >> x & 1){
for(int y : v[x]){
if(mask >> y & 1){
dp[x][mask] += dp[y][mask ^ (1 << x)];
}
}
}
}
}
long long ans = 0;
for(int i = 0;i < n;i ++){
ans += dp[i][(1 << n) - 1];
}
cout << ans << endl;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
