Submission #1816234


Source Code Expand

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
using namespace std;

typedef long long s64;

struct object
{
	int a, b, c, d;
	object() {}
	object(const int &_a, const int &_b, const int &_c, const int &_d)
		: a(_a), b(_b), c(_c), d(_d) {}

	inline s64 value() const
	{
		return ((s64)a << 30) | (b << 20) | (c << 10) | d;
	}

	inline object rotate() const
	{
		return {b, c, d, a};
	}
};
map<s64, int> all;

inline void add(object cur, int delta)
{
	for (int k = 0; k < 4; ++k)
		all[(cur = cur.rotate()).value()] += delta;
}

inline int query(const object &a)
{
	return all[a.value()];
}

inline bool existed(const object &a)
{
	return all.find(a.value()) != all.end();
}

const int MaxN = 400;

int n;
object f[MaxN + 1];

int main()
{
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		cin >> f[i].a >> f[i].b;
		cin >> f[i].c >> f[i].d;
		add(f[i], 1);
	}

	s64 res = 0;
	for (int i = 1; i < n; ++i)
	{
		add(f[i], -1);

		for (int j = i + 1; j <= n; ++j)
		{
			add(f[j], -1);

			object cur = f[j];
			for (int k = 0; k < 4; ++k)
			{
				object f1(cur.b, cur.a, f[i].b, f[i].a);
				object f2(cur.a, cur.d, f[i].c, f[i].b);
				object f3(cur.d, cur.c, f[i].d, f[i].c);
				object f4(cur.c, cur.b, f[i].a, f[i].d);

				if (!existed(f1) || !existed(f2) || !existed(f3) || !existed(f4))
				{
					cur = cur.rotate();
					continue;
				}

				s64 ways = 1;
				ways *= query(f1), add(f1, -1);
				ways *= query(f2), add(f2, -1);
				ways *= query(f3), add(f3, -1);
				ways *= query(f4);

				add(f1, 1), add(f2, 1), add(f3, 1);

				res += ways;

				cur = cur.rotate();
			}

			add(f[j], 1);
		}
	}

	cout << res << endl;

	return 0;
}

Submission Info

Submission Time
Task E - Building Cubes with AtCoDeer
User InvUsr
Language C++14 (GCC 5.4.1)
Score 900
Code Size 1789 Byte
Status AC
Exec Time 293 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 46 ms 256 KB
1_004.txt AC 4 ms 256 KB
1_005.txt AC 77 ms 256 KB
1_006.txt AC 54 ms 256 KB
1_007.txt AC 177 ms 256 KB
1_008.txt AC 157 ms 256 KB
1_009.txt AC 293 ms 256 KB
1_010.txt AC 21 ms 256 KB
1_011.txt AC 66 ms 384 KB
1_012.txt AC 1 ms 256 KB
1_013.txt AC 62 ms 384 KB
1_014.txt AC 2 ms 256 KB
1_015.txt AC 61 ms 384 KB
1_016.txt AC 15 ms 256 KB
1_017.txt AC 61 ms 384 KB
1_018.txt AC 61 ms 384 KB
1_019.txt AC 63 ms 384 KB