Submission #926267

# Submission time Handle Problem Language Result Execution time Memory
926267 2024-02-12T18:06:11 Z samek08 Cards (LMIO19_korteles) C++14
36 / 100
1000 ms 43912 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, p = 2137, mod = 1e9+7;
int n = 0;
ll wyn = 0;
char A[4][MAXN];
unordered_map<int,int> S1;
unordered_map<int,int> S2;
unordered_map<int,int> S3;
unordered_map<int,int> S4;
int POW[10];

inline int convert(string el)
{
	int res = 0, cnt = -1;
	for(auto& x : el)
	{
		++cnt;
		res = ((ll)res+(ll)POW[cnt]*(ll)(x)) % (ll)mod;
	}
	return res;
}

inline void dodaj1(string el)
{
	int x = convert(el);
	if(auto it = S1.find(x) != S1.end()) ++S1[x];
	else S1[x] = 1;
}

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

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

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

inline int licz1(string el)
{
	int x = convert(el);
	if(auto it = S1.find(x) != S1.end()) return S1[x];
	return 0;
}

inline int licz2(string el)
{
	int x = convert(el);
	if(auto it = S2.find(x) != S2.end()) return S2[x];
	return 0;
}

inline int licz3(string el)
{
	int x = convert(el);
	if(auto it = S3.find(x) != S3.end()) return S3[x];
	return 0;
}

inline int licz4(string el)
{
	int x = convert(el);
	if(auto it = S4.find(x) != S4.end()) return S4[x];
	return 0;
}

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

	POW[0] = 1;
	for(int i = 1; i < 10; ++i) POW[i] = ((ll)POW[i-1]*(ll)p) % (ll)mod;

	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]);

		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); 


		wyn += res;

		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]);

		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(std::string)':
korteles.cpp:54:10: warning: unused variable 'it' [-Wunused-variable]
   54 |  if(auto it = S1.find(x) != S1.end()) ++S1[x];
      |          ^~
korteles.cpp: In function 'void dodaj2(std::string)':
korteles.cpp:61:10: warning: unused variable 'it' [-Wunused-variable]
   61 |  if(auto it = S2.find(x) != S2.end()) ++S2[x];
      |          ^~
korteles.cpp: In function 'void dodaj3(std::string)':
korteles.cpp:68:10: warning: unused variable 'it' [-Wunused-variable]
   68 |  if(auto it = S3.find(x) != S3.end()) ++S3[x];
      |          ^~
korteles.cpp: In function 'void dodaj4(std::string)':
korteles.cpp:75:10: warning: unused variable 'it' [-Wunused-variable]
   75 |  if(auto it = S4.find(x) != S4.end()) ++S4[x];
      |          ^~
korteles.cpp: In function 'int licz1(std::string)':
korteles.cpp:82:10: warning: unused variable 'it' [-Wunused-variable]
   82 |  if(auto it = S1.find(x) != S1.end()) return S1[x];
      |          ^~
korteles.cpp: In function 'int licz2(std::string)':
korteles.cpp:89:10: warning: unused variable 'it' [-Wunused-variable]
   89 |  if(auto it = S2.find(x) != S2.end()) return S2[x];
      |          ^~
korteles.cpp: In function 'int licz3(std::string)':
korteles.cpp:96:10: warning: unused variable 'it' [-Wunused-variable]
   96 |  if(auto it = S3.find(x) != S3.end()) return S3[x];
      |          ^~
korteles.cpp: In function 'int licz4(std::string)':
korteles.cpp:103:10: warning: unused variable 'it' [-Wunused-variable]
  103 |  if(auto it = S4.find(x) != S4.end()) return S4[x];
      |          ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 3 ms 860 KB Output is correct
7 Correct 6 ms 860 KB Output is correct
8 Correct 10 ms 1628 KB Output is correct
9 Correct 10 ms 1624 KB Output is correct
10 Correct 10 ms 1372 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 43912 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 Incorrect 275 ms 18372 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 6 ms 860 KB Output is correct
4 Correct 10 ms 1628 KB Output is correct
5 Correct 10 ms 1624 KB Output is correct
6 Correct 10 ms 1372 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Execution timed out 1089 ms 43912 KB Time limit exceeded
13 Halted 0 ms 0 KB -