C. Solution for Cube

f:id:peroon:20201207040304p:plain

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll N=24;
    VI A(N);
    rep(i,N){
      cin>>A[i];
      A[i]--;
    }

    // その面は揃っているか
    auto same = [&](ll a){
      set<ll> se;
      FOR(i,4*a, 4*a+4){
        se.insert(A[i]);
      }
      return se.size()==1;
    };

    // 4つのindexを指定して色が同じか返す
    auto f = [&](ll a, ll b, ll c, ll d){
      set<ll> se;
      se.insert(A[a]);
      se.insert(A[b]);
      se.insert(A[c]);
      se.insert(A[d]);
      return se.size()==1;
    };

    // 0面
    if(same(0) && same(2)){
      // 残りの4面判定
      if(f(4,5,14,15)&&f(16,17,6,7)&&f(20,21,18,19)&&f(12,13,22,23))yes();
      if(f(12,13,6,7)&&f(4,5,18,19)&&f(16,17,22,23)&&f(20,21,14,15))yes();
    }

    if(same(1)&&same(5)){
      if(f(2,3,17,19)&&f(16,18,10,11)&&f(8,9,12,14)&&f(13,15,0,1))yes();
      if(f(2,3,12,14)&&f(16,18,0,1)&&f(8,9,17,19)&&f(13,15,10,11))yes();
    }

    if(same(3)&&same(4)){
      if(f(0,2,5,7)&&f(4,6,9,11)&&f(8,10,22,20)&&f(23,21,1,3))yes();
      if(f(0,2,22,20)&&f(4,6,1,3)&&f(8,10,5,7)&&f(23,21,9,11))yes();
    }

    no();
    return 0;
}