| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 41235 | IvanC | 아름다운 순열 (IZhO12_beauty) | C++14 | 2905 ms | 164708 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 20;
const int MAXL = (1 << 20);
ll dp[MAXN][MAXL];
int adj[MAXN],qtd[MAXN][2],alvo,n;
ll solve(int pos,int bitmask){
if(bitmask == alvo){
return 1;
}
if(dp[pos][bitmask] != -1) return dp[pos][bitmask];
ll tot = 0;
for(int nxt = 0;nxt<n;nxt++){
if(((1 << nxt) & adj[pos]) && !((1 << nxt) & bitmask) ){
tot += solve(nxt, (bitmask) | (1 << nxt) );
}
}
return dp[pos][bitmask] = tot;
}
int main(){
cin >> n;
alvo = (1 << n) - 1;
for(int i = 0;i<n;i++) memset(dp[i],-1,sizeof(dp[i]));
for(int i = 0;i<n;i++){
int x;
cin >> x;
int copia = x;
int copia2 = x;
for(int vez = 0;vez<31;vez++){
if(copia % 2 == 1) qtd[i][0]++;
copia /= 2;
if(copia2 % 3 == 1) qtd[i][1]++;
copia2 /= 3;
}
for(int j = 0;j<i;j++){
if(qtd[i][0] == qtd[j][0]){
adj[j] |= (1 << i);
adj[i] |= (1 << j);
}
if(qtd[i][1] == qtd[j][1]){
adj[j] |= (1 << i);
adj[i] |= (1 << j);
}
}
}
ll tot = 0;
for(int i = 0;i<n;i++) tot += solve(i,(1<<i));
cout << tot << endl;
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
