| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 321199 | kshitij_sodani | 아름다운 순열 (IZhO12_beauty) | C++14 | 833 ms | 164580 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
llo n;
llo it[30];
llo co[30];
llo co2[30];
llo dp[1<<20][20];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
for(llo i=0;i<n;i++){
cin>>it[i];
llo x=it[i];
while(it[i]>0){
llo xx=it[i]%3;
if(xx==1){
co[i]++;
}
it[i]-=xx;
it[i]/=3;
}
it[i]=x;
while(it[i]>0){
llo xx=it[i]%2;
if(xx==1){
co2[i]++;
}
it[i]-=xx;
it[i]/=2;
}
}
llo ans=0;
for(llo i=1;i<(1<<n);i++){
vector<llo> co3;
for(llo j=0;j<n;j++){
if(i&(1<<j)){
co3.pb(j);
}
}
if(co3.size()==1){
dp[i][co3[0]]=1;
}
else{
for(int jj=0;jj<co3.size();jj++){
int j=co3[jj];
for(auto k:co3){
if(co[k]==co[j] or co2[j]==co2[k]){
dp[i][j]+=dp[i-(1<<j)][k];
}
}
}
}
if(co3.size()==n){
for(llo j=0;j<n;j++){
ans+=dp[i][j];
}
}
}
/*for(int i=0;i<n;i++){
cout<<co[i]<<",,";
}
cout<<endl;
for(int i=0;i<n;i++){
cout<<co2[i]<<",,";
}
cout<<endl;
cout<<dp[7][0]<<":"<<dp[7][1]<<":"<<dp[7][2]<<endl;
cout<<dp[3][0]<<":"<<dp[3][1]<<endl;
cout<<dp[2][1]<<endl;*/
cout<<ans<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
