| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 382228 | saarang123 | 아름다운 순열 (IZhO12_beauty) | C++17 | 738 ms | 164588 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int mxn = 20;
long long dp[1 << mxn][mxn];
int a[mxn], bin[mxn], ter[mxn];
signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    #ifdef saarang
    freopen("/home/saarang/Documents/cp/input.txt", "r", stdin);
    freopen("/home/saarang/Documents/cp/output.txt", "w", stdout);
    #endif
    int n; cin >> n;
    for(int i = 0; i < n; i++) {
    	cin >> a[i];
    	int c = 0;
    	for(int j = 0; j < 31; j++)
    		c += (a[i] >> j & 1);
    	bin[i] = c;
    	int f = 0, x = a[i];
    	while(x) {
    		f += (x % 3 == 1);
    		x /= 3;
    	}
    	ter[i] = f;
    }
    for(int i = 0; i < n; i++)
    	dp[1 << i][i] = 1;
    for(int mask = 1; mask < (1 << n); mask++) {
    	for(int i = 0; i < n; i++) if(!(mask >> i & 1)) {
    		for(int j = 0; j < n; j++) if(mask >> j & 1)
    			if(bin[i] == bin[j] || ter[i] == ter[j])
    				dp[mask ^ (1 << i)][i] += dp[mask][j];
    	}
    }
    long long ans = 0;
    for(int i = 0; i < n; i++)
    	ans += dp[(1 << n) - 1][i];
    cout << ans << '\n';
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
