# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
173195 | 2020-01-03T14:50:39 Z | juggernaut | 아름다운 순열 (IZhO12_beauty) | C++14 | 13 ms | 1656 KB |
//Just try and the idea will come! #include<bits/stdc++.h> using namespace std; int n,i,a[20],dp[1048576][20],ans,j,tri[20],bin[20],mask; int main(){ scanf("%d",&n); for(;i<n;i++){ scanf("%d",&a[i]); dp[1<<i][i]=1; bin[i]=__builtin_popcount(a[i]); mask=a[i]; while(mask){ if(mask%3==1)tri[i]++; mask/=3; } } for(mask=0;mask<(1<<n);mask++) for(i=0;i<n;i++) if(mask&(1<<i)) for(j=0;j<n;j++) if(i!=j) if(mask&(1<<j)&&(tri[i]==tri[j]||bin[i]==bin[j]))dp[mask][i]+=dp[mask^(1<<i)][j]; for(i=0;i<n;i++)ans+=dp[(1<<n)-1][i]; printf("%d",ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 252 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 3 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Incorrect | 13 ms | 1656 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |