Submission #254185

# Submission time Handle Problem Language Result Execution time Memory
254185 2020-07-29T13:23:00 Z Berted Cards (LMIO19_korteles) C++14
100 / 100
283 ms 2424 KB
#include <iostream>
#define ll long long
using namespace std;

int n, ar[4][700], ar2[4][700], ar3[500001];
ll res = 0;

inline int getHash1(char a, char b)
{
	return (a - 'A') * 26 + (b - 'A');
}

inline int getHash2(char a, char b, char c, char d)
{
	return (a - 'A') * 17576 + (b - 'A') * 676 + (c - 'A') * 26 + (d - 'A');
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		string a, b; cin >> a >> b;

		res += ar[0][getHash1(b[0], b[1])]; 
		res += ar[1][getHash1(a[1], b[1])];
		res += ar[2][getHash1(a[0], a[1])];
		res += ar[3][getHash1(a[0], b[0])];
		
		ar[0][getHash1(a[0], a[1])]++;
		ar[1][getHash1(a[0], b[0])]++;
		ar[2][getHash1(b[0], b[1])]++;
		ar[3][getHash1(a[1], b[1])]++;
		
		if (a[1] == b[0])
		{
			res -= ar2[0][getHash1(a[0], b[0])];
			res -= ar2[2][getHash1(a[1], b[1])];
			ar2[0][getHash1(a[1], b[1])]++;
			ar2[2][getHash1(a[0], b[0])]++;
		}
		if (a[0] == b[1])
		{
			res -= ar2[1][getHash1(a[1], b[1])];
			res -= ar2[3][getHash1(a[0], b[0])];
			ar2[1][getHash1(a[0], b[0])]++;
			ar2[3][getHash1(a[1], b[1])]++;
		}

		res -= ar3[getHash2(a[1], a[0], b[1], b[0])];
		res -= ar3[getHash2(b[0], b[1], a[0], a[1])];
		if (a[0] == b[1] && a[1] == b[0]) 
		{
			res += 3 * ar3[getHash2(a[1], a[0], a[0], a[1])];
		}
	
		ar3[getHash2(a[0], a[1], b[0], b[1])]++;
	}
	cout << res << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 2 ms 1664 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 3 ms 2176 KB Output is correct
5 Correct 3 ms 1536 KB Output is correct
6 Correct 4 ms 1920 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 283 ms 2424 KB Output is correct
2 Correct 279 ms 2304 KB Output is correct
3 Correct 282 ms 2304 KB Output is correct
4 Correct 282 ms 2304 KB Output is correct
5 Correct 278 ms 2304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 34 ms 2424 KB Output is correct
3 Correct 196 ms 2424 KB Output is correct
4 Correct 109 ms 2304 KB Output is correct
5 Correct 110 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 2 ms 1664 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 3 ms 2176 KB Output is correct
5 Correct 3 ms 1536 KB Output is correct
6 Correct 4 ms 1920 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 512 KB Output is correct
12 Correct 283 ms 2424 KB Output is correct
13 Correct 279 ms 2304 KB Output is correct
14 Correct 282 ms 2304 KB Output is correct
15 Correct 282 ms 2304 KB Output is correct
16 Correct 278 ms 2304 KB Output is correct
17 Correct 34 ms 2424 KB Output is correct
18 Correct 196 ms 2424 KB Output is correct
19 Correct 109 ms 2304 KB Output is correct
20 Correct 110 ms 2296 KB Output is correct
21 Correct 63 ms 2296 KB Output is correct
22 Correct 218 ms 2304 KB Output is correct
23 Correct 137 ms 2304 KB Output is correct
24 Correct 141 ms 2296 KB Output is correct