| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 31103 | TAMREF | Beautiful row (IZhO12_beauty) | C++11 | 1516 ms | 165860 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define bp __builtin_popcount
using namespace std;
inline int tp(int x){
int cnt=0;
for(;x;x/=3) cnt+=(x%3==1);
return cnt;
}
vector<int> G[20];
int N, a[20];
long long tsp[20][1048576];
void init(){
scanf("%d",&N);
for(int i=0;i<N;i++){
scanf("%d",&a[i]);
}
for(int i=0;i<N;i++){
for(int j=i+1;j<N;j++){
if(bp(a[i])==bp(a[j])||tp(a[i])==tp(a[j])){
G[i].push_back(j);
G[j].push_back(i);
}
}
}
for(int i=0;i<N;i++){
tsp[i][1<<i]=1;
}
}
void travel(){
for(int b=1;b<(1<<N)-1;b++){
for(int i=0;i<N;i++){
for(int j : G[i]){
if((b & 1<<j) ==0){
tsp[j][b|(1<<j)]+=tsp[i][b];
}
}
}
}
}
void debug(){
for(int i=0;i<N;i++,puts("")) for(int u : G[i]) printf("%d ",u);
for(int i=0;i<N;i++,puts("")) for(int j=0;j<(1<<N);j++) printf("%d ",tsp[i][j]);
}
int main(){
init();
travel();
long long perm=0;
for(int i=0;i<N;i++) perm+=tsp[i][(1<<N)-1];
printf("%lld\n",perm);
//debug();
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
