Submission #926246

# Submission time Handle Problem Language Result Execution time Memory
926246 2024-02-12T17:49:51 Z samek08 Cards (LMIO19_korteles) C++14
36 / 100
1000 ms 70496 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a,b) for(int a = 0; a < (b); ++a)
#define all(t) t.begin(), t.end()
#define pb push_back

struct Element
{
	string n1, n2, n3, n4;
	bool operator < (const Element &element) const
	{
		//return n1 < element.n1 || n2 < element.n2 || n3 < element.n3 || n4 < element.n4;
		if(n1 == element.n1)
		{
			if(n2 == element.n2)
			{
				if(n3 == element.n3)
				{
					return n4 < element.n4;
				}
				return n3 < element.n3;
			}
			return n2 < element.n2;
		}
		return n1 < element.n1;
	}
};

const int MAXN = 5e5+5;
int n = 0;
ll wyn = 0;
char A[4][MAXN];
map<Element,int> S1;
map<Element,int> S2;
map<Element,int> S3;
map<Element,int> S4;

inline void dodaj1(Element el)
{
	//cout << "n1: " << el.n1 << " n2: " << el.n2 << " n3: " << el.n3 << " n4: " << el.n4 << endl;
	if(auto it = S1.find(el) != S1.end())
	{
		//cout << "JEST" << endl;
		++S1[el];
	}
	else
	{
		//cout << "NIE MA" << endl;
		S1[el] = 1;
	}
}

inline void dodaj2(Element el)
{
	if(auto it = S2.find(el) != S2.end()) ++S2[el];
	else S2[el] = 1;
}

inline void dodaj3(Element el)
{
	if(auto it = S3.find(el) != S3.end()) ++S3[el];
	else S3[el] = 1;
}

inline void dodaj4(Element el)
{
	if(auto it = S4.find(el) != S4.end()) ++S4[el];
	else S4[el] = 1;
}

inline int licz1(Element el)
{
	//cout << "n1: " << el.n1 << " n2: " << el.n2 << " n3: " << el.n3 << " n4: " << el.n4 << endl;
	if(auto it = S1.find(el) != S1.end())
	{
		//cout << "LICZ 1: " << S1[el] << endl;
		return S1[el];
	}
	//cout << "LICZ 1: 0" << endl;
	return 0;
}

inline int licz2(Element el)
{
	//cout << "n1: " << el.n1 << " n2: " << el.n2 << " n3: " << el.n3 << " n4: " << el.n4 << endl;
	if(auto it = S2.find(el) != S2.end())
	{
		//cout << "LICZ 2: " << S2[el] << endl;
		return S2[el];
	}
	return 0;
}

inline int licz3(Element el)
{
	//cout << "n1: " << el.n1 << " n2: " << el.n2 << " n3: " << el.n3 << " n4: " << el.n4 << endl;
	if(auto it = S3.find(el) != S3.end())
	{
	//	cout << "LICZ 3: " << S3[el] << endl;
		return S3[el];
	}
	return 0;
}

inline int licz4(Element el)
{
	//cout << "n1: " << el.n1 << " n2: " << el.n2 << " n3: " << el.n3 << " n4: " << el.n4 << endl;
	if(auto it = S4.find(el) != S4.end())
	{
		//cout << "LICZ 4: " << S4[el] << endl;
		return S4[el];
	}
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n;
	rep(i,n) rep(j,4) cin >> A[j][i];

	rep(i,n)
	{
		string z0, z1, z2, z3, dod = "z";

		int res = 0;

		z0.pb(A[0][i]), z0.pb(A[2][i]);
		z1.pb(A[1][i]), z1.pb(A[3][i]);
		z2.pb(A[0][i]), z2.pb(A[1][i]);
		z3.pb(A[2][i]), z3.pb(A[3][i]);

		//cout << "DODDD: " << dod << " Z0: " << z0 << " Z1: " << z1 << " Z2: " << z2 << " Z3: " << z3 << endl; 

		//cout << "LICZZZZ: " << endl;
		res += licz1({z0,dod,dod,dod});
		res += licz1({dod,z1,dod,dod});
		res += licz1({dod,dod,z2,dod});
		res += licz1({dod,dod,dod,z3});

		res -= licz2({z0,z1,dod,dod});
		res -= licz2({z0,dod,z2,dod});
		res -= licz2({z0,dod,dod,z3});
		res -= licz2({dod,z1,z2,dod});
		res -= licz2({dod,z1,dod,z3});
		res -= licz2({dod,dod,z2,z3});

		res += licz3({z0,z1,z2,dod});
		res += licz3({z0,z1,dod,z3});
		res += licz3({z0,dod,z2,z3});
		res += licz3({dod,z1,z2,z3}); 

		res -= licz4({z0,z1,z2,z3}); 

		//cout << "I: " << i << " RES: " << res << endl;
		//cout << "MAPPP: " << endl;
		//for(auto it = S1.begin(); it != S1.end(); ++it)
		//cout << it->first.n1 << ' ' << it->first.n2 << ' ' << it->first.n3 << ' ' << it->first.n4 << ' ' << it->second << endl;
		//cout << endl << endl;

		wyn += res;
		//cout << "I: " << i << " RES: " << res << endl;

		//cout << endl << endl;

		z0.clear(), z1.clear(), z2.clear(), z3.clear();
		z0.pb(A[1][i]), z0.pb(A[3][i]);
		z1.pb(A[0][i]), z1.pb(A[2][i]);
		z2.pb(A[2][i]), z2.pb(A[3][i]);
		z3.pb(A[0][i]), z3.pb(A[1][i]);

		//cout << "DOD: " << dod << " Z0: " << z0 << " Z1: " << z1 << " Z2: " << z2 << " Z3: " << z3 << endl; 

		//cout << "DODDDDD: " << endl;
		dodaj1({z0,dod,dod,dod});
		dodaj1({dod,z1,dod,dod});
		dodaj1({dod,dod,z2,dod});
		dodaj1({dod,dod,dod,z3});

		dodaj2({z0,z1,dod,dod});
		dodaj2({z0,dod,z2,dod});
		dodaj2({z0,dod,dod,z3});
		dodaj2({dod,z1,z2,dod});
		dodaj2({dod,z1,dod,z3});
		dodaj2({dod,dod,z2,z3});

		dodaj3({z0,z1,z2,dod});
		dodaj3({z0,z1,dod,z3});
		dodaj3({z0,dod,z2,z3});
		dodaj3({dod,z1,z2,z3}); 

		dodaj4({z0,z1,z2,z3}); 
	}

	cout << wyn << '\n';

	return 0;
}

Compilation message

korteles.cpp: In function 'void dodaj1(Element)':
korteles.cpp:42:10: warning: unused variable 'it' [-Wunused-variable]
   42 |  if(auto it = S1.find(el) != S1.end())
      |          ^~
korteles.cpp: In function 'void dodaj2(Element)':
korteles.cpp:56:10: warning: unused variable 'it' [-Wunused-variable]
   56 |  if(auto it = S2.find(el) != S2.end()) ++S2[el];
      |          ^~
korteles.cpp: In function 'void dodaj3(Element)':
korteles.cpp:62:10: warning: unused variable 'it' [-Wunused-variable]
   62 |  if(auto it = S3.find(el) != S3.end()) ++S3[el];
      |          ^~
korteles.cpp: In function 'void dodaj4(Element)':
korteles.cpp:68:10: warning: unused variable 'it' [-Wunused-variable]
   68 |  if(auto it = S4.find(el) != S4.end()) ++S4[el];
      |          ^~
korteles.cpp: In function 'int licz1(Element)':
korteles.cpp:75:10: warning: unused variable 'it' [-Wunused-variable]
   75 |  if(auto it = S1.find(el) != S1.end())
      |          ^~
korteles.cpp: In function 'int licz2(Element)':
korteles.cpp:87:10: warning: unused variable 'it' [-Wunused-variable]
   87 |  if(auto it = S2.find(el) != S2.end())
      |          ^~
korteles.cpp: In function 'int licz3(Element)':
korteles.cpp:98:10: warning: unused variable 'it' [-Wunused-variable]
   98 |  if(auto it = S3.find(el) != S3.end())
      |          ^~
korteles.cpp: In function 'int licz4(Element)':
korteles.cpp:109:10: warning: unused variable 'it' [-Wunused-variable]
  109 |  if(auto it = S4.find(el) != S4.end())
      |          ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1884 KB Output is correct
7 Correct 21 ms 2644 KB Output is correct
8 Correct 34 ms 5468 KB Output is correct
9 Correct 34 ms 4544 KB Output is correct
10 Correct 40 ms 4692 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1032 ms 70496 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 1022 ms 65728 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 7 ms 1884 KB Output is correct
3 Correct 21 ms 2644 KB Output is correct
4 Correct 34 ms 5468 KB Output is correct
5 Correct 34 ms 4544 KB Output is correct
6 Correct 40 ms 4692 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Execution timed out 1032 ms 70496 KB Time limit exceeded
13 Halted 0 ms 0 KB -