Submission #894618

# Submission time Handle Problem Language Result Execution time Memory
894618 2023-12-28T14:31:30 Z Andrey Beautiful row (IZhO12_beauty) C++14
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

int 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 = 1;
    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;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -