Submission #1531315


Source Code Expand

#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a);i<=(b);i++)
using namespace std;
long long a[405];
long long x[405][4];
long long c[405][10];
map<long long,int>m;
long long get(long long x,long long y,long long z,long long h)
{
    long long ret = x;
    ret = (ret<<10)+y;
    ret = (ret<<10)+z;
    ret = (ret<<10)+h;
    return ret;
}
long long pack(long long x,long long y,long long z,long long h)
{
    return min(min(get(x,y,z,h),get(y,z,h,x)),min(get(z,h,x,y),get(h,x,y,z)));
}
long long fac(long long x)
{
    long long ret = 1;
    FOR(i,1,x)ret*=i;
    return ret;
}
long long rot(long long key)
{
    int k[4];
    FOR(i,0,3)
    {
        k[i] = key&((1<<10)-1);
        key>>=10;
    }
    if(k[0] == k[1]&&k[1] == k[2]&&k[2] == k[3])return 4;
    if(k[0] == k[2]&&k[1] == k[3])return 2;
    return 1;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
        c[1][0] = c[1][1] = 1;
        FOR(i,2,n)
        {
            c[i][0] = 1;
            FOR(j,1,min(4,i-1))c[i][j] = c[i-1][j]+c[i-1][j-1];
            c[i][i] = 1;
        }
        FOR(i,1,n)
        {
            FOR(j,0,3)cin>>x[i][j];
            a[i] = pack(x[i][0],x[i][1],x[i][2],x[i][3]);
        }
        long long ans = 0;
        m.clear();
        FOR(i,1,n)
        {
            FOR(ii,1,i-1)
            {
                FOR(j,0,3)
                {
                    long long y[4];
                    y[0] = pack(x[ii][(j+1)%4],x[ii][(j+0)%4],x[i][1],x[i][0]);
                    y[1] = pack(x[ii][(j+0)%4],x[ii][(j+3)%4],x[i][2],x[i][1]);
                    y[2] = pack(x[ii][(j+3)%4],x[ii][(j+2)%4],x[i][3],x[i][2]);
                    y[3] = pack(x[ii][(j+2)%4],x[ii][(j+1)%4],x[i][0],x[i][3]);
 
                    sort(y,y+4);
                    long long ret = 1;
                    for(int p = 0;p<4;)
                    {
                        int cnt = 1;
                        for(int r = p+1;r<4&&y[r] == y[p];r++)cnt++;
                        int num = m.count(y[p])?m[y[p]]:0;
                        if(y[p] == a[ii])num--;
                        if(num<cnt)
                        {
                            ret = 0;
                            break;
                        }
                        ret*=c[num][cnt]*pow(rot(y[p]),cnt)*fac(cnt);
                        p+=cnt;
                    }
                    ans+=ret;
                }
            }
            if(m.count(a[i]))m[a[i]]++;
            else m[a[i]] = 1;
        }
        cout<<ans<<endl;
    return 0;
}

Submission Info

Submission Time
Task E - Building Cubes with AtCoDeer
User xuyuan
Language C++14 (GCC 5.4.1)
Score 900
Code Size 2654 Byte
Status AC
Exec Time 64 ms
Memory 384 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 900 / 900
Status
AC × 3
AC × 20
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt
Case Name Status Exec Time Memory
0_000.txt AC 1 ms 256 KB
0_001.txt AC 1 ms 256 KB
0_002.txt AC 1 ms 256 KB
1_003.txt AC 39 ms 256 KB
1_004.txt AC 4 ms 256 KB
1_005.txt AC 38 ms 256 KB
1_006.txt AC 28 ms 256 KB
1_007.txt AC 54 ms 256 KB
1_008.txt AC 49 ms 256 KB
1_009.txt AC 64 ms 384 KB
1_010.txt AC 7 ms 256 KB
1_011.txt AC 32 ms 384 KB
1_012.txt AC 1 ms 256 KB
1_013.txt AC 28 ms 384 KB
1_014.txt AC 1 ms 256 KB
1_015.txt AC 28 ms 384 KB
1_016.txt AC 9 ms 256 KB
1_017.txt AC 28 ms 384 KB
1_018.txt AC 28 ms 384 KB
1_019.txt AC 28 ms 384 KB