Submission #1356015
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 *= (4 / Period(h)) * (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;
static int Period(ulong h) => h % p2 == 0 ? h % p1 == 0 ? 1 : 2 : 4;
}
Submission Info
Submission Time |
|
Task |
E - Building Cubes with AtCoDeer |
User |
selpo |
Language |
C# (Mono 4.6.2.0) |
Score |
900 |
Code Size |
2452 Byte |
Status |
AC |
Exec Time |
300 ms |
Memory |
17612 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
900 / 900 |
Status |
|
|
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 |
26 ms |
9312 KB |
0_001.txt |
AC |
27 ms |
11360 KB |
0_002.txt |
AC |
27 ms |
13408 KB |
1_003.txt |
AC |
97 ms |
15552 KB |
1_004.txt |
AC |
31 ms |
11360 KB |
1_005.txt |
AC |
256 ms |
15612 KB |
1_006.txt |
AC |
191 ms |
15520 KB |
1_007.txt |
AC |
300 ms |
17612 KB |
1_008.txt |
AC |
273 ms |
17500 KB |
1_009.txt |
AC |
261 ms |
15576 KB |
1_010.txt |
AC |
50 ms |
17608 KB |
1_011.txt |
AC |
94 ms |
13584 KB |
1_012.txt |
AC |
27 ms |
11348 KB |
1_013.txt |
AC |
82 ms |
13508 KB |
1_014.txt |
AC |
27 ms |
11476 KB |
1_015.txt |
AC |
85 ms |
13496 KB |
1_016.txt |
AC |
42 ms |
17588 KB |
1_017.txt |
AC |
84 ms |
15556 KB |
1_018.txt |
AC |
83 ms |
13512 KB |
1_019.txt |
AC |
84 ms |
13524 KB |