제출 #589182

#제출 시각아이디문제언어결과실행 시간메모리
589182mat_jurCards (LMIO19_korteles)C++14
100 / 100
121 ms5056 KiB
#include <bits/stdc++.h>
using namespace std;

const int A = 27;
int wyst[A][A][A][A];

int main () {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n;
	cin >> n;
	long long wyn = 0;
	for (int i = 1; i <= n; i++) {
		string s;
		int a, b, c, d;
		cin >> s;
		a = s[0]-'A'; b = s[1]-'A';
		cin >> s;
		d = s[0]-'A'; c = s[1]-'A';
		int x = 26;
		wyn += wyst[d][c][26][26]; //stykaja sie z dolem
		wyn += wyst[b][26][26][c]; //stykaja sie z prawa
		wyn += wyst[26][26][b][a]; //stykaja sie z gora
		wyn += wyst[26][a][d][26]; //stykaja sie z lewa
		if (a == c)	{
			wyn -= wyst[b][x][b][a];
			wyn -= wyst[d][c][d][x];
		}
		if (b == d) {
			wyn -= wyst[b][c][x][c];
			wyn -= wyst[x][a][d][a];
		}
		wyn -= wyst[d][c][b][a];
		wyn -= wyst[b][a][d][c];
		if (a == c && b == d) {
			wyn += 3*wyst[b][c][b][c];
		}
		
		
		
		wyst[a][b][26][26]++;
		wyst[26][b][c][26]++;
		wyst[26][26][c][d]++;
		wyst[a][26][26][d]++;
		wyst[a][x][c][d]++;
		wyst[a][b][c][x]++;
		wyst[a][b][x][d]++;
		wyst[x][b][c][d]++;
		wyst[a][b][c][d]++;
	}
	
	cout << wyn << "\n";
	
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...