답안 #90108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
90108 2018-12-20T09:55:59 Z Bodo171 아름다운 순열 (IZhO12_beauty) C++14
100 / 100
1064 ms 173140 KB
#include <iostream>

using namespace std;
long long dp[(1<<20)+1][21];
long long ans;
int a[25],b[25];
int n,x,i,j,k;
int cnt(int x,int b)
{
    int ret=0;
    while(x)
    {
        ret+=(x%b==1);
        x/=b;
    }
    return ret;
}
int main()
{
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>x;
        a[i]=cnt(x,2);
        b[i]=cnt(x,3);
    }
    for(i=0;i<n;i++)
        dp[(1<<i)][i]=1;
    for(i=0;i<(1<<n);i++)
        for(j=0;j<n;j++)
           if(((1<<j)&i))
             for(k=0;k<n;k++)
               if((a[j]==a[k]||b[j]==b[k])&&(!((1<<k)&i)))
                   dp[(1<<k)+i][k]+=dp[i][j];
    for(i=0;i<n;i++)
        ans+=dp[(1<<n)-1][i];
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 444 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 448 KB Output is correct
6 Correct 2 ms 696 KB Output is correct
7 Correct 2 ms 696 KB Output is correct
8 Correct 3 ms 696 KB Output is correct
9 Correct 3 ms 720 KB Output is correct
10 Correct 3 ms 720 KB Output is correct
11 Correct 12 ms 3240 KB Output is correct
12 Correct 11 ms 3364 KB Output is correct
13 Correct 49 ms 11328 KB Output is correct
14 Correct 218 ms 43668 KB Output is correct
15 Correct 217 ms 43668 KB Output is correct
16 Correct 211 ms 43668 KB Output is correct
17 Correct 224 ms 43772 KB Output is correct
18 Correct 189 ms 43772 KB Output is correct
19 Correct 1064 ms 173140 KB Output is correct
20 Correct 926 ms 173140 KB Output is correct