Submission #674493

# Submission time Handle Problem Language Result Execution time Memory
674493 2022-12-24T14:26:47 Z Sohsoh84 Cubeword (CEOI19_cubeword) C++17
84 / 100
645 ms 98516 KB
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define all(x)			(x).begin(),(x).end()
#define X			first
#define Y			second
#define sep			' '
#define endl			'\n'
#define debug(x)		cerr << #x << ": " <<  x << endl;

constexpr ll MAXN = 1e6 + 10;
constexpr ll MAXM = 26 + 26;
constexpr ll MOD = 998244353;

inline int f(char c) {
	if (c >= 'a' && c <= 'z') return c - 'a';
	else if (c >= 'A' && c <= 'Z') return c - 'A' + 26;
	return c - '0' + 26 + 26;
}

ll F[MAXM][MAXM], T[MAXM][MAXM][MAXM], ans;
int n, nxt[MAXN][MAXM], sz = 0;
vector<string> vec[MAXM];

inline bool add(string s) {
	int v = 0;
	bool flag = false;

	for (char c : s) {
		if (!nxt[v][f(c)]) {
			flag = true;
			nxt[v][f(c)] = ++sz;
		}

		v = nxt[v][f(c)];
	}

	return flag;
}

inline void solve(int len) {
	memset(F, 0, sizeof F);
	memset(T, 0, sizeof T);
	for (int i = 0; i <= sz; i++)
		memset(nxt[i], 0, sizeof nxt[i]);
	sz = 0;

	for (string s : vec[len])
		if (add(s))
			F[f(s.front())][f(s.back())]++;
	
	for (int i = 0; i < MAXM; i++)
		for (int j = 0; j < MAXM; j++)
			for (int k = 0; k < MAXM; k++)
				for (int a = 0; a < MAXM; a++)
					T[i][j][k] = (T[i][j][k] + F[a][i] * F[a][j] * F[a][k]) % MOD;

	for (int a = 0; a < MAXM; a++)
		for (int b = 0; b < MAXM; b++)
			for (int c = 0; c < MAXM; c++)
				for (int d = 0; d < MAXM; d++)
					ans = (ans + T[a][b][c] * T[a][b][d] % MOD * T[a][c][d] % MOD * T[b][c][d]) % MOD;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t;
	cin >> t;
	while (t--) {
		string s;
		cin >> s;

		vec[s.size()].push_back(s);
		reverse(all(s));
		vec[s.size()].push_back(s);
	}

	for (int i = 3; i <= 10; i++)
		solve(i);

	cout << ans << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 557 ms 46168 KB Output is correct
2 Correct 555 ms 45936 KB Output is correct
3 Correct 553 ms 46064 KB Output is correct
4 Correct 558 ms 46136 KB Output is correct
5 Correct 555 ms 45940 KB Output is correct
6 Correct 556 ms 45540 KB Output is correct
7 Correct 556 ms 45772 KB Output is correct
8 Correct 555 ms 45640 KB Output is correct
9 Correct 551 ms 45540 KB Output is correct
10 Correct 567 ms 45916 KB Output is correct
11 Correct 559 ms 45996 KB Output is correct
12 Correct 549 ms 45848 KB Output is correct
13 Correct 562 ms 45968 KB Output is correct
14 Correct 569 ms 45576 KB Output is correct
15 Correct 562 ms 45304 KB Output is correct
16 Correct 554 ms 45652 KB Output is correct
17 Correct 557 ms 45744 KB Output is correct
18 Correct 553 ms 45696 KB Output is correct
19 Correct 560 ms 45548 KB Output is correct
20 Correct 555 ms 45716 KB Output is correct
21 Correct 552 ms 45648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 557 ms 46168 KB Output is correct
2 Correct 555 ms 45936 KB Output is correct
3 Correct 553 ms 46064 KB Output is correct
4 Correct 558 ms 46136 KB Output is correct
5 Correct 555 ms 45940 KB Output is correct
6 Correct 556 ms 45540 KB Output is correct
7 Correct 556 ms 45772 KB Output is correct
8 Correct 555 ms 45640 KB Output is correct
9 Correct 551 ms 45540 KB Output is correct
10 Correct 567 ms 45916 KB Output is correct
11 Correct 559 ms 45996 KB Output is correct
12 Correct 549 ms 45848 KB Output is correct
13 Correct 562 ms 45968 KB Output is correct
14 Correct 569 ms 45576 KB Output is correct
15 Correct 562 ms 45304 KB Output is correct
16 Correct 554 ms 45652 KB Output is correct
17 Correct 557 ms 45744 KB Output is correct
18 Correct 553 ms 45696 KB Output is correct
19 Correct 560 ms 45548 KB Output is correct
20 Correct 555 ms 45716 KB Output is correct
21 Correct 552 ms 45648 KB Output is correct
22 Correct 562 ms 47164 KB Output is correct
23 Correct 565 ms 47156 KB Output is correct
24 Correct 571 ms 47252 KB Output is correct
25 Correct 558 ms 47540 KB Output is correct
26 Correct 567 ms 47024 KB Output is correct
27 Correct 568 ms 47596 KB Output is correct
28 Correct 562 ms 47520 KB Output is correct
29 Correct 565 ms 47256 KB Output is correct
30 Correct 563 ms 47756 KB Output is correct
31 Correct 556 ms 47576 KB Output is correct
32 Correct 565 ms 47504 KB Output is correct
33 Correct 561 ms 47432 KB Output is correct
34 Correct 558 ms 47656 KB Output is correct
35 Correct 558 ms 47112 KB Output is correct
36 Correct 560 ms 47188 KB Output is correct
37 Correct 553 ms 47568 KB Output is correct
38 Correct 564 ms 47348 KB Output is correct
39 Correct 562 ms 47260 KB Output is correct
40 Correct 556 ms 47452 KB Output is correct
41 Correct 556 ms 47500 KB Output is correct
42 Correct 569 ms 46948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 557 ms 46168 KB Output is correct
2 Correct 555 ms 45936 KB Output is correct
3 Correct 553 ms 46064 KB Output is correct
4 Correct 558 ms 46136 KB Output is correct
5 Correct 555 ms 45940 KB Output is correct
6 Correct 556 ms 45540 KB Output is correct
7 Correct 556 ms 45772 KB Output is correct
8 Correct 555 ms 45640 KB Output is correct
9 Correct 551 ms 45540 KB Output is correct
10 Correct 567 ms 45916 KB Output is correct
11 Correct 559 ms 45996 KB Output is correct
12 Correct 549 ms 45848 KB Output is correct
13 Correct 562 ms 45968 KB Output is correct
14 Correct 569 ms 45576 KB Output is correct
15 Correct 562 ms 45304 KB Output is correct
16 Correct 554 ms 45652 KB Output is correct
17 Correct 557 ms 45744 KB Output is correct
18 Correct 553 ms 45696 KB Output is correct
19 Correct 560 ms 45548 KB Output is correct
20 Correct 555 ms 45716 KB Output is correct
21 Correct 552 ms 45648 KB Output is correct
22 Correct 562 ms 47164 KB Output is correct
23 Correct 565 ms 47156 KB Output is correct
24 Correct 571 ms 47252 KB Output is correct
25 Correct 558 ms 47540 KB Output is correct
26 Correct 567 ms 47024 KB Output is correct
27 Correct 568 ms 47596 KB Output is correct
28 Correct 562 ms 47520 KB Output is correct
29 Correct 565 ms 47256 KB Output is correct
30 Correct 563 ms 47756 KB Output is correct
31 Correct 556 ms 47576 KB Output is correct
32 Correct 565 ms 47504 KB Output is correct
33 Correct 561 ms 47432 KB Output is correct
34 Correct 558 ms 47656 KB Output is correct
35 Correct 558 ms 47112 KB Output is correct
36 Correct 560 ms 47188 KB Output is correct
37 Correct 553 ms 47568 KB Output is correct
38 Correct 564 ms 47348 KB Output is correct
39 Correct 562 ms 47260 KB Output is correct
40 Correct 556 ms 47452 KB Output is correct
41 Correct 556 ms 47500 KB Output is correct
42 Correct 569 ms 46948 KB Output is correct
43 Correct 579 ms 47668 KB Output is correct
44 Correct 574 ms 48144 KB Output is correct
45 Correct 576 ms 48036 KB Output is correct
46 Correct 574 ms 48252 KB Output is correct
47 Correct 576 ms 47984 KB Output is correct
48 Correct 585 ms 48912 KB Output is correct
49 Correct 575 ms 48036 KB Output is correct
50 Correct 575 ms 48884 KB Output is correct
51 Correct 574 ms 48576 KB Output is correct
52 Correct 577 ms 47916 KB Output is correct
53 Correct 578 ms 47932 KB Output is correct
54 Correct 575 ms 48464 KB Output is correct
55 Correct 584 ms 48572 KB Output is correct
56 Correct 602 ms 48116 KB Output is correct
57 Correct 574 ms 48276 KB Output is correct
58 Correct 575 ms 48232 KB Output is correct
59 Correct 576 ms 48032 KB Output is correct
60 Correct 577 ms 47976 KB Output is correct
61 Correct 607 ms 48180 KB Output is correct
62 Correct 592 ms 48288 KB Output is correct
63 Correct 591 ms 48036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 557 ms 46168 KB Output is correct
2 Correct 555 ms 45936 KB Output is correct
3 Correct 553 ms 46064 KB Output is correct
4 Correct 558 ms 46136 KB Output is correct
5 Correct 555 ms 45940 KB Output is correct
6 Correct 556 ms 45540 KB Output is correct
7 Correct 556 ms 45772 KB Output is correct
8 Correct 555 ms 45640 KB Output is correct
9 Correct 551 ms 45540 KB Output is correct
10 Correct 567 ms 45916 KB Output is correct
11 Correct 559 ms 45996 KB Output is correct
12 Correct 549 ms 45848 KB Output is correct
13 Correct 562 ms 45968 KB Output is correct
14 Correct 569 ms 45576 KB Output is correct
15 Correct 562 ms 45304 KB Output is correct
16 Correct 554 ms 45652 KB Output is correct
17 Correct 557 ms 45744 KB Output is correct
18 Correct 553 ms 45696 KB Output is correct
19 Correct 560 ms 45548 KB Output is correct
20 Correct 555 ms 45716 KB Output is correct
21 Correct 552 ms 45648 KB Output is correct
22 Correct 562 ms 47164 KB Output is correct
23 Correct 565 ms 47156 KB Output is correct
24 Correct 571 ms 47252 KB Output is correct
25 Correct 558 ms 47540 KB Output is correct
26 Correct 567 ms 47024 KB Output is correct
27 Correct 568 ms 47596 KB Output is correct
28 Correct 562 ms 47520 KB Output is correct
29 Correct 565 ms 47256 KB Output is correct
30 Correct 563 ms 47756 KB Output is correct
31 Correct 556 ms 47576 KB Output is correct
32 Correct 565 ms 47504 KB Output is correct
33 Correct 561 ms 47432 KB Output is correct
34 Correct 558 ms 47656 KB Output is correct
35 Correct 558 ms 47112 KB Output is correct
36 Correct 560 ms 47188 KB Output is correct
37 Correct 553 ms 47568 KB Output is correct
38 Correct 564 ms 47348 KB Output is correct
39 Correct 562 ms 47260 KB Output is correct
40 Correct 556 ms 47452 KB Output is correct
41 Correct 556 ms 47500 KB Output is correct
42 Correct 569 ms 46948 KB Output is correct
43 Correct 579 ms 47668 KB Output is correct
44 Correct 574 ms 48144 KB Output is correct
45 Correct 576 ms 48036 KB Output is correct
46 Correct 574 ms 48252 KB Output is correct
47 Correct 576 ms 47984 KB Output is correct
48 Correct 585 ms 48912 KB Output is correct
49 Correct 575 ms 48036 KB Output is correct
50 Correct 575 ms 48884 KB Output is correct
51 Correct 574 ms 48576 KB Output is correct
52 Correct 577 ms 47916 KB Output is correct
53 Correct 578 ms 47932 KB Output is correct
54 Correct 575 ms 48464 KB Output is correct
55 Correct 584 ms 48572 KB Output is correct
56 Correct 602 ms 48116 KB Output is correct
57 Correct 574 ms 48276 KB Output is correct
58 Correct 575 ms 48232 KB Output is correct
59 Correct 576 ms 48032 KB Output is correct
60 Correct 577 ms 47976 KB Output is correct
61 Correct 607 ms 48180 KB Output is correct
62 Correct 592 ms 48288 KB Output is correct
63 Correct 591 ms 48036 KB Output is correct
64 Runtime error 645 ms 98516 KB Execution killed with signal 11
65 Halted 0 ms 0 KB -