# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
701985 | Darren0724 | 아름다운 순열 (IZhO12_beauty) | C++17 | 1500 ms | 172748 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define int long long
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;cin>>n;
vector<int> v(n);
vector<int> a(n),b(n);
for(int i=0;i<n;i++){
cin>>v[i];
}
for(int i=0;i<n;i++){
int p=v[i];
while(p>0){
if(p%3==1){
a[i]++;
}
p/=3;
}
p=v[i];
while(p>0){
if(p%2==1){
b[i]++;
}
p/=2;
}
}
vector<vector<int>> dp(n,vector<int>(1<<n));
for(int i=0;i<n;i++){
dp[i][1<<i]=1;
}
for(int i=1;i<(1<<n);i++){
for(int j=0;j<n;j++){
if(i&(1<<j)){
for(int k1=0;k1<n;k1++){
if(a[j]==a[k1]||b[j]==b[k1]){
dp[j][i]+=dp[k1][i-(1<<j)];
}
}
}
}
}
int ans=0;
for(int i=0;i<n;i++){
ans+=dp[i][(1<<n)-1];
}
cout<<ans<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |