Submission #786435

# Submission time Handle Problem Language Result Execution time Memory
786435 2023-07-18T07:46:23 Z blue Cubeword (CEOI19_cubeword) C++17
84 / 100
247 ms 36208 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
#define sz(x) int(x.size())

const ll mod = 998'244'353LL;

const int Z = 32;

int ad(ll a, ll b)
{
	return (a + b) % mod;
}

void selfadd(int& a, ll b)
{
	a = ad(a, b);
}

int mul(ll a, ll b)
{
	return (a * b) % mod;
}

int getnum(char c)
{
	// if('a' <= c && c <= 'z')
	// 	return c - 'a';
	// else if('A' <= c && c <= 'Z')
	// 	return 26 + c - 'A';
	// else if('0' <= c && c <= '9')
	// 	return 26 + 26 + c - '0';
	// else
	// 	assert(0);

	if('a' <= c && c <= 'z')
		return c - 'a';
	else
		return 16 + c - 'A';
}


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

	int n;
	cin >> n;

	set<string> words;

	for(int i = 1; i <= n; i++)
	{
		string s;
		cin >> s;

		words.insert(s);

		reverse(s.begin(), s.end());

		words.insert(s);
	}

	vector<pii> wl[11];

	for(string w : words)
	{
		wl[sz(w)].push_back({getnum(w[0]), getnum(w.back())});
	}


// cerr << "done\n";

	int res = 0;

	for(int l = 3; l <= 10; l++)
	{
		// cerr << "l = " << l << '\n';
		vvi ct(Z, vi(Z, 0));

		for(pii z : wl[l])
		{
			ct[z.first][z.second]++;
		}

		vvvi ct3(Z, vvi(Z, vi(Z, 0)));

		for(int a = 0; a < Z; a++)
		{
			for(int b = 0; b < Z; b++)
			{
				for(int c = 0; c < Z; c++)
				{
					for(int x = 0; x < Z; x++)
					{
						selfadd(ct3[a][b][c], mul(ct[x][a], mul(ct[x][b], ct[x][c])));
					}
				}
			}
		}

		for(int a = 0; a < Z; a++)
		{
			for(int b = 0; b < Z; b++)
			{
				for(int c = 0; c < Z; c++)
				{
					for(int d = 0; d < Z; d++)
					{
						selfadd(res, mul(ct3[a][b][c], mul(ct3[b][c][d], mul(ct3[c][d][a], ct3[d][a][b]))));
					}
				}
			}
		}
	}

	cout << res << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 211 ms 16508 KB Output is correct
2 Correct 191 ms 16448 KB Output is correct
3 Correct 202 ms 16536 KB Output is correct
4 Correct 213 ms 16548 KB Output is correct
5 Correct 189 ms 16824 KB Output is correct
6 Correct 215 ms 16676 KB Output is correct
7 Correct 199 ms 16520 KB Output is correct
8 Correct 197 ms 16736 KB Output is correct
9 Correct 217 ms 16460 KB Output is correct
10 Correct 195 ms 16524 KB Output is correct
11 Correct 212 ms 16488 KB Output is correct
12 Correct 201 ms 16440 KB Output is correct
13 Correct 214 ms 16556 KB Output is correct
14 Correct 191 ms 16484 KB Output is correct
15 Correct 197 ms 16484 KB Output is correct
16 Correct 210 ms 16684 KB Output is correct
17 Correct 193 ms 16680 KB Output is correct
18 Correct 189 ms 16724 KB Output is correct
19 Correct 211 ms 16828 KB Output is correct
20 Correct 194 ms 16728 KB Output is correct
21 Correct 197 ms 16476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 16508 KB Output is correct
2 Correct 191 ms 16448 KB Output is correct
3 Correct 202 ms 16536 KB Output is correct
4 Correct 213 ms 16548 KB Output is correct
5 Correct 189 ms 16824 KB Output is correct
6 Correct 215 ms 16676 KB Output is correct
7 Correct 199 ms 16520 KB Output is correct
8 Correct 197 ms 16736 KB Output is correct
9 Correct 217 ms 16460 KB Output is correct
10 Correct 195 ms 16524 KB Output is correct
11 Correct 212 ms 16488 KB Output is correct
12 Correct 201 ms 16440 KB Output is correct
13 Correct 214 ms 16556 KB Output is correct
14 Correct 191 ms 16484 KB Output is correct
15 Correct 197 ms 16484 KB Output is correct
16 Correct 210 ms 16684 KB Output is correct
17 Correct 193 ms 16680 KB Output is correct
18 Correct 189 ms 16724 KB Output is correct
19 Correct 211 ms 16828 KB Output is correct
20 Correct 194 ms 16728 KB Output is correct
21 Correct 197 ms 16476 KB Output is correct
22 Correct 205 ms 17200 KB Output is correct
23 Correct 209 ms 17248 KB Output is correct
24 Correct 198 ms 17260 KB Output is correct
25 Correct 205 ms 17116 KB Output is correct
26 Correct 196 ms 17092 KB Output is correct
27 Correct 197 ms 17440 KB Output is correct
28 Correct 196 ms 17396 KB Output is correct
29 Correct 218 ms 17136 KB Output is correct
30 Correct 194 ms 17108 KB Output is correct
31 Correct 198 ms 17248 KB Output is correct
32 Correct 227 ms 17404 KB Output is correct
33 Correct 195 ms 17252 KB Output is correct
34 Correct 198 ms 17352 KB Output is correct
35 Correct 209 ms 17176 KB Output is correct
36 Correct 191 ms 17392 KB Output is correct
37 Correct 211 ms 17160 KB Output is correct
38 Correct 191 ms 17256 KB Output is correct
39 Correct 207 ms 17288 KB Output is correct
40 Correct 193 ms 17136 KB Output is correct
41 Correct 201 ms 17256 KB Output is correct
42 Correct 226 ms 17232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 16508 KB Output is correct
2 Correct 191 ms 16448 KB Output is correct
3 Correct 202 ms 16536 KB Output is correct
4 Correct 213 ms 16548 KB Output is correct
5 Correct 189 ms 16824 KB Output is correct
6 Correct 215 ms 16676 KB Output is correct
7 Correct 199 ms 16520 KB Output is correct
8 Correct 197 ms 16736 KB Output is correct
9 Correct 217 ms 16460 KB Output is correct
10 Correct 195 ms 16524 KB Output is correct
11 Correct 212 ms 16488 KB Output is correct
12 Correct 201 ms 16440 KB Output is correct
13 Correct 214 ms 16556 KB Output is correct
14 Correct 191 ms 16484 KB Output is correct
15 Correct 197 ms 16484 KB Output is correct
16 Correct 210 ms 16684 KB Output is correct
17 Correct 193 ms 16680 KB Output is correct
18 Correct 189 ms 16724 KB Output is correct
19 Correct 211 ms 16828 KB Output is correct
20 Correct 194 ms 16728 KB Output is correct
21 Correct 197 ms 16476 KB Output is correct
22 Correct 205 ms 17200 KB Output is correct
23 Correct 209 ms 17248 KB Output is correct
24 Correct 198 ms 17260 KB Output is correct
25 Correct 205 ms 17116 KB Output is correct
26 Correct 196 ms 17092 KB Output is correct
27 Correct 197 ms 17440 KB Output is correct
28 Correct 196 ms 17396 KB Output is correct
29 Correct 218 ms 17136 KB Output is correct
30 Correct 194 ms 17108 KB Output is correct
31 Correct 198 ms 17248 KB Output is correct
32 Correct 227 ms 17404 KB Output is correct
33 Correct 195 ms 17252 KB Output is correct
34 Correct 198 ms 17352 KB Output is correct
35 Correct 209 ms 17176 KB Output is correct
36 Correct 191 ms 17392 KB Output is correct
37 Correct 211 ms 17160 KB Output is correct
38 Correct 191 ms 17256 KB Output is correct
39 Correct 207 ms 17288 KB Output is correct
40 Correct 193 ms 17136 KB Output is correct
41 Correct 201 ms 17256 KB Output is correct
42 Correct 226 ms 17232 KB Output is correct
43 Correct 192 ms 17640 KB Output is correct
44 Correct 209 ms 18432 KB Output is correct
45 Correct 218 ms 18268 KB Output is correct
46 Correct 208 ms 18108 KB Output is correct
47 Correct 210 ms 18168 KB Output is correct
48 Correct 200 ms 18224 KB Output is correct
49 Correct 210 ms 18148 KB Output is correct
50 Correct 193 ms 18184 KB Output is correct
51 Correct 195 ms 18380 KB Output is correct
52 Correct 211 ms 18272 KB Output is correct
53 Correct 195 ms 18180 KB Output is correct
54 Correct 196 ms 18268 KB Output is correct
55 Correct 218 ms 18256 KB Output is correct
56 Correct 198 ms 18216 KB Output is correct
57 Correct 206 ms 18324 KB Output is correct
58 Correct 214 ms 18156 KB Output is correct
59 Correct 195 ms 18288 KB Output is correct
60 Correct 195 ms 18284 KB Output is correct
61 Correct 247 ms 18212 KB Output is correct
62 Correct 221 ms 18260 KB Output is correct
63 Correct 195 ms 18432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 16508 KB Output is correct
2 Correct 191 ms 16448 KB Output is correct
3 Correct 202 ms 16536 KB Output is correct
4 Correct 213 ms 16548 KB Output is correct
5 Correct 189 ms 16824 KB Output is correct
6 Correct 215 ms 16676 KB Output is correct
7 Correct 199 ms 16520 KB Output is correct
8 Correct 197 ms 16736 KB Output is correct
9 Correct 217 ms 16460 KB Output is correct
10 Correct 195 ms 16524 KB Output is correct
11 Correct 212 ms 16488 KB Output is correct
12 Correct 201 ms 16440 KB Output is correct
13 Correct 214 ms 16556 KB Output is correct
14 Correct 191 ms 16484 KB Output is correct
15 Correct 197 ms 16484 KB Output is correct
16 Correct 210 ms 16684 KB Output is correct
17 Correct 193 ms 16680 KB Output is correct
18 Correct 189 ms 16724 KB Output is correct
19 Correct 211 ms 16828 KB Output is correct
20 Correct 194 ms 16728 KB Output is correct
21 Correct 197 ms 16476 KB Output is correct
22 Correct 205 ms 17200 KB Output is correct
23 Correct 209 ms 17248 KB Output is correct
24 Correct 198 ms 17260 KB Output is correct
25 Correct 205 ms 17116 KB Output is correct
26 Correct 196 ms 17092 KB Output is correct
27 Correct 197 ms 17440 KB Output is correct
28 Correct 196 ms 17396 KB Output is correct
29 Correct 218 ms 17136 KB Output is correct
30 Correct 194 ms 17108 KB Output is correct
31 Correct 198 ms 17248 KB Output is correct
32 Correct 227 ms 17404 KB Output is correct
33 Correct 195 ms 17252 KB Output is correct
34 Correct 198 ms 17352 KB Output is correct
35 Correct 209 ms 17176 KB Output is correct
36 Correct 191 ms 17392 KB Output is correct
37 Correct 211 ms 17160 KB Output is correct
38 Correct 191 ms 17256 KB Output is correct
39 Correct 207 ms 17288 KB Output is correct
40 Correct 193 ms 17136 KB Output is correct
41 Correct 201 ms 17256 KB Output is correct
42 Correct 226 ms 17232 KB Output is correct
43 Correct 192 ms 17640 KB Output is correct
44 Correct 209 ms 18432 KB Output is correct
45 Correct 218 ms 18268 KB Output is correct
46 Correct 208 ms 18108 KB Output is correct
47 Correct 210 ms 18168 KB Output is correct
48 Correct 200 ms 18224 KB Output is correct
49 Correct 210 ms 18148 KB Output is correct
50 Correct 193 ms 18184 KB Output is correct
51 Correct 195 ms 18380 KB Output is correct
52 Correct 211 ms 18272 KB Output is correct
53 Correct 195 ms 18180 KB Output is correct
54 Correct 196 ms 18268 KB Output is correct
55 Correct 218 ms 18256 KB Output is correct
56 Correct 198 ms 18216 KB Output is correct
57 Correct 206 ms 18324 KB Output is correct
58 Correct 214 ms 18156 KB Output is correct
59 Correct 195 ms 18288 KB Output is correct
60 Correct 195 ms 18284 KB Output is correct
61 Correct 247 ms 18212 KB Output is correct
62 Correct 221 ms 18260 KB Output is correct
63 Correct 195 ms 18432 KB Output is correct
64 Runtime error 102 ms 36208 KB Execution killed with signal 11
65 Halted 0 ms 0 KB -