| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 370650 | MilosMilutinovic | Beautiful row (IZhO12_beauty) | C++14 | 848 ms | 164676 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxN = 20;
int n, a[mxN];
ll dp[1<<mxN][mxN];
bool con[mxN][mxN];
int cnt(int x) {
int res=0;
while(x)
res+=x%2, x/=2;
return res;
}
int cnt1(int x) {
int res=0;
while(x)
res+=(x%3==1?1:0), x/=3;
return res;
}
int main() {
cin >> n;
for(int i=0; i<n; ++i) {
cin >> a[i];
dp[1<<i][i]=1;
}
for(int i=0; i<n; ++i)
for(int j=0; j<n; ++j)
if(cnt(a[i])==cnt(a[j])||cnt1(a[i])==cnt1(a[j]))
con[i][j]=true;
for(int i=1; i<(1<<n); ++i) {
for(int j=0; j<n; ++j) {
if(i&(1<<j)) {
for(int k=0; k<n; ++k) {
if((i>>k)&1^1&&con[j][k]){
dp[i|(1<<k)][k]+=dp[i][j];
}
}
}
}
}
ll ans = 0;
for(int i=0; i<n; ++i)
ans+=dp[(1<<n)-1][i];
cout << ans << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
