Submission #1521450


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using Square = array<int, 4>;

map<Square, ll> memo;

const Square indices[] = {{1,0,1,0},{2,1,0,3},{3,2,3,2},{0,3,2,1}};

void normalize(Square& s) {
	set<Square> tmp;
	for (int i = 0; i < 4; i++) {
		tmp.insert(s);
		rotate(s.begin(), s.begin() + 1, s.end());
	}
	s = *tmp.begin();
}

int pattern(Square& s) {
	if (s[0] == s[2] && s[1] == s[3]) {
		if (s[0] == s[1]) return 4;
		else return 2;
	}
	return 1;
}

ll solve(const Square& s1, const Square& s2) {
	ll res = 1;
	int used = -1;
	for (int i = 0; i < 4; i++) {
		Square tmp = {s1[indices[i][0]], s1[indices[i][1]], s2[indices[i][2]], s2[indices[i][3]]};
		normalize(tmp);
		if (memo.find(tmp) == memo.end() || memo[tmp] == 0) {
			res = 0;
			break;
		}
		res *= memo[tmp] * pattern(tmp);
		memo[tmp]--;
		used++;
	}

	for (int i = 0; i <= used; i++) {
		Square tmp = {s1[indices[i][0]], s1[indices[i][1]], s2[indices[i][2]], s2[indices[i][3]]};
		normalize(tmp);
		memo[tmp]++;	
	}
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<Square> c(n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 4; j++) {
			cin >> c[i][j];
		}
		normalize(c[i]);
		memo[c[i]]++;
	}

	ll ans = 0;
	for (int i = 0; i < n; i++) {
		memo[c[i]]--;
		for (int j = 0; j < i; j++) {
			memo[c[j]]--;
			for (int k = 0; k < 4; k++) {
				ans += solve(c[i], c[j]);
				rotate(c[j].begin(), c[j].begin() + 1, c[j].end());
			}
			memo[c[j]]++;
		}
		memo[c[i]]++;	
	}
	cout << ans / 3 << endl;
	return 0;
}

Submission Info

Submission Time
Task E - Building Cubes with AtCoDeer
User fine
Language C++14 (GCC 5.4.1)
Score 900
Code Size 1642 Byte
Status AC
Exec Time 845 ms
Memory 256 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 394 ms 256 KB
1_004.txt AC 29 ms 256 KB
1_005.txt AC 749 ms 256 KB
1_006.txt AC 512 ms 256 KB
1_007.txt AC 845 ms 256 KB
1_008.txt AC 756 ms 256 KB
1_009.txt AC 843 ms 256 KB
1_010.txt AC 66 ms 256 KB
1_011.txt AC 166 ms 256 KB
1_012.txt AC 2 ms 256 KB
1_013.txt AC 110 ms 256 KB
1_014.txt AC 2 ms 256 KB
1_015.txt AC 112 ms 256 KB
1_016.txt AC 30 ms 256 KB
1_017.txt AC 111 ms 256 KB
1_018.txt AC 110 ms 256 KB
1_019.txt AC 110 ms 256 KB