# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
682099 | Hydrolyzed | 아름다운 순열 (IZhO12_beauty) | C++14 | 79 ms | 164472 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MxN = 20;
ll dp[1 << MxN][MxN], a[MxN];
int count_three(ll x){
int response = 0;
while(x > 0){
response += (x % 3 == 1);
x /= 3;
}
return response;
}
bool ok(ll a, ll b){
return (__builtin_popcountll(a) == __builtin_popcountll(b) || count_three(a) == count_three(b));
}
void solve(){
memset(dp, 0, sizeof dp);
int n;
scanf("%d", &n);
for(int i=0; i<n; ++i){
scanf("%lld", &a[i]);
dp[1 << i][i] = 1;
}
for(int state=1; state<(1 << n); ++state){
for(int i=0; i<n; ++i){
if(!(state & (1 << i))){
continue;
}
for(int j=0; j<n; ++j){
if(state & (1 << j)){
continue;
}
if(ok(a[i], a[j])){
dp[state ^ (1 << j)][j] += dp[state][i];
}
}
}
}
ll answer = 0ll;
for(int i=0; i<n; ++i){
answer = answer + dp[(1 << n) - 1][i];
}
printf("%lld", answer);
}
int main(){
int q;
scanf("%d", &q);
while(q--){
solve();
printf("\n");
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |