Submission #1356019


Source Code Expand

using System.Collections.Generic;
using System.Linq;
using System;
using static System.Math;
using static System.Console;
class E { static void Main() => new K(); }
class K
{
	public K()
	{
		var N = int.Parse(ReadLine());
		var surf = new uint[N][];
		var per = new int[N];
		var hash = new ulong[N];
		var dict = new Dictionary<ulong, int>();
		for (var i = 0; i < N; i++)
		{
			surf[i] = ReadLine().Split().Select(uint.Parse).ToArray();
			per[i] = surf[i][0] == surf[i][2] && surf[i][1] == surf[i][3] ? surf[i][0] == surf[i][1] ? 1 : 2 : 4;
			if (per[i] == 1) hash[i] = Hash1(surf[i][0]);
			else if (per[i] == 2) hash[i] = Hash2(surf[i][0], surf[i][1]);
			else hash[i] = Hash(surf[i][0], surf[i][1], surf[i][2], surf[i][3]);
			if (!dict.ContainsKey(hash[i])) dict[hash[i]] = 0;
			dict[hash[i]]++;
		}
		var a = 0L;
		var y = new uint[4];
		for (var i = 0; i < N; i++)
			for (var j = i + 1; j < N; j++)
			{
				var count = 0L;
				dict[hash[i]]--;
				dict[hash[j]]--;
				for (var rj = 0; rj < per[j]; rj++)
				{
					var x = surf[i];
					for (var k = 0; k < 4; k++) y[k] = surf[j][(k + rj) % 4];
					var s = new[] {
						Hash(y[3], y[2], x[3], x[2]),
						Hash(y[2], y[1], x[0], x[3]),
						Hash(y[1], y[0], x[1], x[0]),
						Hash(y[0], y[3], x[2], x[1])
					};
					var p = 1L;
					var dup = new Dictionary<ulong, int>();
					foreach (var h in s)
					{
						if (!dict.ContainsKey(h)) { p = 0; break; }
						if (!dup.ContainsKey(h)) dup[h] = 0;
						p *= (h % p2 == 0 ? h % p1 == 0 ? 4 : 2 : 1) * (dict[h] - dup[h]);
						dup[h]++;
					}
					count += p;
				}
				a += count * (4 / per[j]);
				dict[hash[i]]++;
				dict[hash[j]]++;
			}
		WriteLine(a / 3);
	}
	static ulong Hash(uint i, uint j, uint k, uint l)
	{
		var a = ((ulong)i << 30) | (j << 20) | (k << 10) | l;
		a = Min(a, ((ulong)j << 30) | (k << 20) | (l << 10) | i);
		a = Min(a, ((ulong)k << 30) | (l << 20) | (i << 10) | j);
		a = Min(a, ((ulong)l << 30) | (i << 20) | (j << 10) | k);
		return a;
	}
	static ulong Hash1(uint i) => ((ulong)i << 30) | (i << 20) | (i << 10) | i;
	static ulong Hash2(uint i, uint j)
	{
		if (i > j) return ((ulong)j << 30) | (i << 20) | (j << 10) | i;
		return ((ulong)i << 30) | (j << 20) | (i << 10) | j;
	}
	const ulong p1 = (1 << 30) | (1 << 20) | (1 << 10) | 1;
	const ulong p2 = (1 << 20) | 1;
}

Submission Info

Submission Time
Task E - Building Cubes with AtCoDeer
User selpo
Language C# (Mono 4.6.2.0)
Score 900
Code Size 2405 Byte
Status AC
Exec Time 289 ms
Memory 17612 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 28 ms 11488 KB
0_001.txt AC 26 ms 11360 KB
0_002.txt AC 26 ms 11360 KB
1_003.txt AC 92 ms 13504 KB
1_004.txt AC 31 ms 11360 KB
1_005.txt AC 247 ms 15528 KB
1_006.txt AC 187 ms 15636 KB
1_007.txt AC 289 ms 15528 KB
1_008.txt AC 264 ms 15536 KB
1_009.txt AC 256 ms 15544 KB
1_010.txt AC 48 ms 17608 KB
1_011.txt AC 94 ms 15632 KB
1_012.txt AC 27 ms 13396 KB
1_013.txt AC 82 ms 17596 KB
1_014.txt AC 26 ms 9312 KB
1_015.txt AC 81 ms 15544 KB
1_016.txt AC 42 ms 17588 KB
1_017.txt AC 81 ms 13588 KB
1_018.txt AC 83 ms 15636 KB
1_019.txt AC 84 ms 17612 KB