Submission #976715


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef vector<int> vi;

inline vi normarize(const vi &v)
{
    vector<vi> r(4);
    rep(i,4)
    {
        vi t(4);
        rep(j,4) t[j]=v[(i+j)%4];
        r[i]=t;
    }
    sort(all(r));
    return r[0];
}

inline ll DIM(const vi &v)
{
    if(v[0]==v[1] && v[1]==v[2] && v[2]==v[3]) return 4;
    if(v[0]==v[2] && v[1]==v[3]) return 2;
    return 1;
}

int main()
{
    ll P[401][5]={0};
    for(int i=1; i<=400; ++i)
    {
        P[i][1]=i;
        for(int j=2; j<=min(4,i); ++j) P[i][j]=P[i][j-1]*(i-j+1);
    }

    ll POW[5][5];
    rep(i,5)
    {
        POW[i][0]=1;
        for(int j=1; j<5; ++j) POW[i][j]=POW[i][j-1]*i;
    }

    int n;
    scanf(" %d", &n);

    vector<vi> c(n,vi(4));
    rep(i,n)rep(j,4) scanf(" %d", &c[i][j]);

    map<vi,int> ct;
    rep(i,n)
    {
        c[i]=normarize(c[i]);
        if(ct.find(c[i])==ct.end()) ct[c[i]]=1;
        else ++ct[c[i]];
    }

    ll ans=0;
    // 上面i, 下面j, 下面の向きを設定
    rep(i,n)rep(j,i)rep(k,4)
    {
        vi u(4);
        rep(x,4) u[x]=c[j][(k+x)%4];
        swap(u[1],u[3]);

        vector<vi> sides(4);
        rep(x,4)
        {
            vi t(4);
            t[0]=c[i][(x+1)%4];
            t[1]=c[i][x];
            t[2]=u[x];
            t[3]=u[(x+1)%4];
            sides[x]=normarize(t);
        }
        sort(all(sides));

        ll add=1;
        int idx=0, st=0;
        while(1)
        {
            while(idx<4 && sides[st]==sides[idx]) ++idx;
            vi key=sides[st];
            int value=idx-st;

            // 使ってないタイルのうち当てはめられる個数
            int num=ct[key];
            if(c[i]==key) --num;
            if(c[j]==key) --num;

            if(num<value)
            {
                add=0;
                break;
            }

            // 選び方、向き、位置
            add*=P[num][value]*POW[DIM(key)][value];

            if(idx==4) break;
            st=idx;
        }
        ans+=add;
    }

    // 向かい合う面の個数ぶん重複する
    cout << ans/3 << endl;
    return 0;
}

Submission Info

Submission Time
Task E - Building Cubes with AtCoDeer
User imulan
Language C++14 (GCC 5.4.1)
Score 900
Code Size 2483 Byte
Status AC
Exec Time 947 ms
Memory 35200 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:51:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf(" %d", &n);
                     ^
./Main.cpp:54:44: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     rep(i,n)rep(j,4) scanf(" %d", &c[i][j]);
                                            ^

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 3 ms 256 KB
0_001.txt AC 3 ms 256 KB
0_002.txt AC 3 ms 256 KB
1_003.txt AC 727 ms 256 KB
1_004.txt AC 54 ms 256 KB
1_005.txt AC 765 ms 256 KB
1_006.txt AC 546 ms 256 KB
1_007.txt AC 833 ms 256 KB
1_008.txt AC 744 ms 256 KB
1_009.txt AC 873 ms 256 KB
1_010.txt AC 120 ms 256 KB
1_011.txt AC 764 ms 512 KB
1_012.txt AC 7 ms 384 KB
1_013.txt AC 915 ms 31104 KB
1_014.txt AC 11 ms 640 KB
1_015.txt AC 935 ms 35200 KB
1_016.txt AC 259 ms 9856 KB
1_017.txt AC 947 ms 35200 KB
1_018.txt AC 920 ms 35200 KB
1_019.txt AC 945 ms 34816 KB