mayoko’s diary

プロコンとかいろいろ。

SRM 484 div2 hard: CubeColoring

div2 med のほうが難しい説ある。

解法

0, 2, 5, 7 を決めると, それ以外の頂点は 隣り合った要素と別ので Y ならどんな色を使っても OK です。よって, 0, 2, 5, 7 の色について全探索して, 残りの色が何通りあるのかを調べれば良いです。

class CubeColoring {
public:
    long long theCount(vector <string> colors) {
        ll ans = 0;
        int n = colors[0].size();
        for (int c0 = 0; c0 < n; c0++) for (int c2 = 0; c2 < n; c2++) {
            for (int c5 = 0; c5 < n; c5++) for (int c7 = 0; c7 < n; c7++) {
                if (colors[0][c0] == 'N') continue;
                if (colors[2][c2] == 'N') continue;
                if (colors[5][c5] == 'N') continue;
                if (colors[7][c7] == 'N') continue;
                ll c1 = 0, c3 = 0, c4 = 0, c6 = 0;
                for (int i = 0; i < n; i++) {
                    if (colors[1][i] == 'Y' && c0 != i && c2 != i && c5 != i) c1++;
                    if (colors[3][i] == 'Y' && c0 != i && c2 != i && c7 != i) c3++;
                    if (colors[4][i] == 'Y' && c0 != i && c5 != i && c7 != i) c4++;
                    if (colors[6][i] == 'Y' && c2 != i && c5 != i && c7 != i) c6++;
                }
                ans += c1*c3*c4*c6;
            }
        }
        return ans;
    }
};