# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
673821 | smartmonky | 아름다운 순열 (IZhO12_beauty) | C++14 | 751 ms | 172740 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
//void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
const int N = (1 << 20) + 1;
long long dp[N][21];
int a[22], bit[22], ter[22];
long long ful = 0;
int getbits(int x){
int res = 0;
while(x > 0){
res += x % 2;
x >>= 1;
}
return res;
}
int getter(int x){
int res = 0;
while(x > 0){
res += (x % 3 == 1);
x /= 3;
}
return res;
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for(int i = 0; i < n; i++){
ful += (1 << i);
cin >> a[i];
bit[i] = getbits(a[i]);
ter[i] = getter(a[i]);
dp[(1 << i)][i] = 1;
}
for(int i = 0; i < (1 << (n)); i++){
for(int j = 0; j < n; j++){
if(dp[i][j] == 0 || (i & (1 << j)) == 0)continue;
for(int k = 0; k < n; k++){
if((i & (1 << k)) || i + (1 << k) > ful)continue;
if(bit[k] == bit[j] || ter[k] == ter[j])
dp[i + (1 << k)][k] += dp[i][j];
}
}
}
long long ans = 0;
for(int i = 0; i < n; i++){
ans += dp[ful][i];
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |