Submission #931467


Source Code Expand

Copy
#include <iostream>
#include <unordered_map>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

i64 comp(const vi &a) {
    i64 res = 0;
    forn(i, 4) res = 1000 * res + a[i];
    return res;
}

i64 comp2(vi a) {
    i64 ans = 1e18;
    forn(i, 4) {
        uin(ans, comp(a));
        rotate(a.begin(), a.begin() + 1, a.end());
    }
    return ans;
}

int autom(const vi &a) {
    if (a[0] == a[1] && a[1] == a[2] && a[2] == a[3]) return 4;
    if (a[0] == a[2] && a[1] == a[3]) return 2;
    return 1;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n;
    cin >> n;
    vector<vvi> a(4, vvi(n, vi(4)));
    forn(i, n) forn(j, 4) cin >> a[0][i][j];
    forn(i, 3) forn(j, n) a[i + 1][j] = a[i][j], rotate(a[i + 1][j].begin(), a[i + 1][j].begin() + 1, a[i + 1][j].end());

    vi64 ca(n);
    forn(j, n) ca[j] = comp2(a[0][j]);

    i64 ans = 0;
    forn(i, n) forn(j, i) {
        forn(d, 4) {
            map<i64, int> cnt, aut;
            forn(k, 4) {
                vi v = {a[0][i][k], a[d][j][(4 - k) % 4], a[d][j][(3 - k) % 4], a[0][i][(k + 1) % 4]};
                i64 z = comp2(v);
                ++cnt[z]; aut[z] = autom(v);
            }
            vi64 have;
            forn(k, i) {
                if (k == j) continue;
                have.pb(ca[k]);
            }
            sort(all(have));
            i64 res = 1;
            int l = 0;
            while (l < have.size()) {
                i64 x = have[l];
                int r = l;
                while (r < have.size() && have[r] == x) ++r;
                if (cnt.count(x)) {
                    int k = cnt[x], y = r - l, z = aut[x];
                    forn(i, k) {
                        res *= y - i;
                        res *= z;
                    }
                    cnt.erase(x);
                }
                l = r;
            }
            if (!cnt.empty()) res = 0;
            ans += res;
        }
//        if (!j) cerr << i << '\n';
    }
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

Submission Info

Submission Time
Task E - Building Cubes with AtCoDeer
User endagorion
Language C++14 (GCC 5.4.1)
Score 900
Code Size 3421 Byte
Status AC
Exec Time 2772 ms
Memory 512 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 3 ms 256 KB
0_001.txt AC 3 ms 256 KB
0_002.txt AC 3 ms 256 KB
1_003.txt AC 1257 ms 512 KB
1_004.txt AC 43 ms 256 KB
1_005.txt AC 1613 ms 384 KB
1_006.txt AC 991 ms 384 KB
1_007.txt AC 2072 ms 384 KB
1_008.txt AC 1739 ms 384 KB
1_009.txt AC 2724 ms 384 KB
1_010.txt AC 171 ms 256 KB
1_011.txt AC 2772 ms 384 KB
1_012.txt AC 5 ms 256 KB
1_013.txt AC 2718 ms 384 KB
1_014.txt AC 8 ms 256 KB
1_015.txt AC 2700 ms 384 KB
1_016.txt AC 400 ms 384 KB
1_017.txt AC 2702 ms 384 KB
1_018.txt AC 2684 ms 384 KB
1_019.txt AC 2673 ms 384 KB