답안 #894621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894621 2023-12-28T14:33:26 Z Andrey 아름다운 순열 (IZhO12_beauty) C++14
0 / 100
7 ms 4700 KB
#include <bits/stdc++.h>
using namespace std;

long long dp[(1 << 20)][20];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,a;
    cin >> n;
    vector<int> haha(n);
    for(int i = 0; i < n; i++) {
        cin >> haha[i];
    }
    vector<int> br2(n);
    vector<int> br3(n);
    for(int i = 0; i < n; i++) {
        a = haha[i];
        while(a > 0) {
            br2[i]+=a%2;
            a/=2;
        }
        a = haha[i];
        while(a > 0) {
            if(a%3 == 1) {
                br3[i]+=1;
            }
            a/=3;
        }
    }
    int ans = 0;
    for(int i = 1; i < (1 << n); i++) {
        for(int j = 0; j < n; j++) {
            if((1 << j)&i) {
                int c = i-(1 << j);
                dp[i][j] = 0;
                if(c == 0) {
                    dp[i][j] = 1;
                }
                else {
                    for(int k = 0; k < n; k++) {
                        if(((1 << k)&c) && (br2[k] == br2[j] || br3[k] == br3[j])) {
                            if(dp[c][k] != -1) {
                                dp[i][j]+=dp[c][k];
                            }
                        }
                    }
                }
            }
            else {
                dp[i][j] = 0;
            }
        }
    }
    for(int i = 0; i < n; i++) {
        ans+=dp[(1 << n)-1][i];
    }
    cout << ans;
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 856 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Incorrect 7 ms 4700 KB Output isn't correct
12 Halted 0 ms 0 KB -