Submission #1349280


Source Code Expand

#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
typedef long long int64;
static const int MAXN = 418;
static const int MAXC = 1002;

int n;
struct tile {
    int val[4];
    int64 _hash;

    inline void normalize() {
        static int nw[4];
        static int64 h[4];
        for (int i = 0; i < 4; ++i)
            h[i] = (((int64)val[i] * MAXC + val[(i + 1) % 4]) * MAXC + val[(i + 2) % 4]) * MAXC + val[(i + 3) % 4];
        int x = std::min_element(h, h + 4) - &h[0];
        for (int i = 0; i < 4; ++i) nw[i] = val[(i + x) % 4];
        for (int i = 0; i < 4; ++i) val[i] = nw[i];
    }
    inline void shift() {
        int x = val[0]; val[0] = val[1]; val[1] = val[2]; val[2] = val[3]; val[3] = x;
    }
    inline int64 hash() {
        if (_hash != -1) return _hash;
        static int nw[4];
        for (int i = 0; i < 4; ++i) nw[i] = val[i];
        this->normalize();
        int64 ans = (((int64)val[0] * MAXC + val[1]) * MAXC + val[2]) * MAXC + val[3];
        for (int i = 0; i < 4; ++i) val[i] = nw[i];
        return (_hash = ans);
    }
    inline int rotations() {
        if (val[0] == val[2] && val[1] == val[3]) {
            if (val[0] == val[1]) return 4; else return 2;
        } else return 1;
    }

    tile() : _hash(-1) { }
    tile(int a, int b, int c, int d) : _hash(-1) { val[0] = a, val[1] = b, val[2] = c, val[3] = d; this->hash(); }
} c[MAXN];

inline bool operator < (const tile &lhs, const tile &rhs) { return lhs._hash < rhs._hash; }

std::map< int64, std::vector<int> > counter;

inline int count(int64 hash, int lower)
{
    std::map< int64, std::vector<int> >::iterator p = counter.find(hash);
    if (p == counter.end()) return 0;
    return std::distance(std::lower_bound(p->second.begin(), p->second.end(), lower), p->second.end());
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d%d%d", &c[i].val[0], &c[i].val[1], &c[i].val[2], &c[i].val[3]);
        c[i].normalize();
        counter[c[i].hash()].push_back(i);
    }

    int64 ans = 0;
    tile t[4];
    for (int i = 0; i < n - 1; ++i)
        for (int j = i + 1; j < n; ++j)
            for (int k = 0; k < 4; ++k) {
                t[0] = tile(c[i].val[1], c[i].val[0], c[j].val[1], c[j].val[0]);
                t[1] = tile(c[i].val[2], c[i].val[1], c[j].val[0], c[j].val[3]);
                t[2] = tile(c[i].val[3], c[i].val[2], c[j].val[3], c[j].val[2]);
                t[3] = tile(c[i].val[0], c[i].val[3], c[j].val[2], c[j].val[1]);
                std::sort(t, t + 4);

                int64 cur = 1;
                for (int p = 0, q; p < 4; p = q) {
                    for (q = p + 1; q < 4 && t[p].hash() == t[q].hash(); ++q) ;
                    int ct = count(t[p].hash(), i + 1), sel = q - p;
                    if (t[p].hash() == c[j].hash()) --ct;
                    for (int k = 1; k <= sel; ++k) cur = cur * (ct - k + 1) * t[p].rotations();
                }
                ans += cur;

                c[j].shift();
            }

    printf("%lld\n", ans);
    return 0;
}

Submission Info

Submission Time
Task E - Building Cubes with AtCoDeer
User cyand1317
Language C++14 (GCC 5.4.1)
Score 900
Code Size 3158 Byte
Status AC
Exec Time 93 ms
Memory 256 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:58:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
./Main.cpp:60:82: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d%d", &c[i].val[0], &c[i].val[1], &c[i].val[2], &c[i].val[3]);
                                                                                  ^

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 46 ms 256 KB
1_004.txt AC 4 ms 256 KB
1_005.txt AC 56 ms 256 KB
1_006.txt AC 41 ms 256 KB
1_007.txt AC 66 ms 256 KB
1_008.txt AC 58 ms 256 KB
1_009.txt AC 86 ms 256 KB
1_010.txt AC 13 ms 256 KB
1_011.txt AC 93 ms 256 KB
1_012.txt AC 2 ms 256 KB
1_013.txt AC 85 ms 256 KB
1_014.txt AC 2 ms 256 KB
1_015.txt AC 82 ms 256 KB
1_016.txt AC 22 ms 256 KB
1_017.txt AC 82 ms 256 KB
1_018.txt AC 83 ms 256 KB
1_019.txt AC 84 ms 256 KB