# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1017923 | LM1 | 아름다운 순열 (IZhO12_beauty) | C++14 | 427 ms | 180864 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define bin __builtin_popcount
#define ll long long
#define int long long
#define pb push_back
#define ff first
#define ss second
using namespace std;
const int N=22;
int fix[N][N],dp[(1<<N)][N];
int ter(int x){
int aa=0;
while(x>0){
if(x%3==1)aa++;
x/=3;
}
return aa;
}
main(){
int n;cin>>n;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(bin(a[i])==bin(a[j])){
fix[i][j]=1;
fix[j][i]=1;
continue;
}
if(ter(a[i])==ter(a[j])){
fix[i][j]=1;
fix[j][i]=1;
continue;
}
}
}
int ans=0;
for(int i=1;i<(1<<n);i++){
vector<int>v;
for(int j=0;j<n;j++)if((1<<j)&i)v.pb(j);
if(bin(i)==1){
dp[i][v[0]]=1;
continue;
}
for(int j=0;j<v.size();j++){
int l=v[j];
for(int k=0;k<v.size();k++){
int l1=v[k];
if(j==k)continue;
if(fix[l][l1])dp[i][l]+=dp[i^(1<<l)][l1];
}
if(i==(1<<n)-1)ans+=dp[i][l];
}
}
cout<<ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |