# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
339835 | nandonathaniel | 아름다운 순열 (IZhO12_beauty) | C++14 | 3063 ms | 164664 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int MAXN=20;
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
int n;
long long dp[1<<MAXN][MAXN];
int a[MAXN];
int binary(int x){
return __builtin_popcount(x);
}
int ternary(int x){
int ret=0;
while(x>0){
if(x%3==1)ret++;
x/=3;
}
return ret;
}
long long DP(int mask,int last){
if(mask==((1<<n)-1))return 1;
long long &ret=dp[mask][last];
if(ret!=-1)return ret;
ret=0;
for(int i=0;i<n;i++){
if(!(mask & (1<<i))){
if(binary(a[last])==binary(a[i]) || ternary(a[last])==ternary(a[i]))ret+=DP(mask+(1<<i),i);
}
}
return ret;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n;
for(int i=0;i<n;i++)cin >> a[i];
memset(dp,-1,sizeof(dp));
long long ans=0;
for(int i=0;i<n;i++)ans+=DP(1<<i,i);
cout << ans << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |