답안 #674492

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674492 2022-12-24T14:25:09 Z Sohsoh84 Cubeword (CEOI19_cubeword) C++17
84 / 100
933 ms 428928 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);
	memset(nxt, 0, sizeof nxt);
	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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 749 ms 211580 KB Output is correct
2 Correct 773 ms 211616 KB Output is correct
3 Correct 762 ms 211536 KB Output is correct
4 Correct 758 ms 211632 KB Output is correct
5 Correct 743 ms 211632 KB Output is correct
6 Correct 739 ms 211780 KB Output is correct
7 Correct 768 ms 211488 KB Output is correct
8 Correct 747 ms 211536 KB Output is correct
9 Correct 750 ms 211680 KB Output is correct
10 Correct 747 ms 211648 KB Output is correct
11 Correct 741 ms 211776 KB Output is correct
12 Correct 745 ms 211736 KB Output is correct
13 Correct 744 ms 211644 KB Output is correct
14 Correct 741 ms 211532 KB Output is correct
15 Correct 743 ms 211560 KB Output is correct
16 Correct 742 ms 211584 KB Output is correct
17 Correct 748 ms 211612 KB Output is correct
18 Correct 749 ms 211484 KB Output is correct
19 Correct 746 ms 211584 KB Output is correct
20 Correct 745 ms 211604 KB Output is correct
21 Correct 741 ms 211628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 749 ms 211580 KB Output is correct
2 Correct 773 ms 211616 KB Output is correct
3 Correct 762 ms 211536 KB Output is correct
4 Correct 758 ms 211632 KB Output is correct
5 Correct 743 ms 211632 KB Output is correct
6 Correct 739 ms 211780 KB Output is correct
7 Correct 768 ms 211488 KB Output is correct
8 Correct 747 ms 211536 KB Output is correct
9 Correct 750 ms 211680 KB Output is correct
10 Correct 747 ms 211648 KB Output is correct
11 Correct 741 ms 211776 KB Output is correct
12 Correct 745 ms 211736 KB Output is correct
13 Correct 744 ms 211644 KB Output is correct
14 Correct 741 ms 211532 KB Output is correct
15 Correct 743 ms 211560 KB Output is correct
16 Correct 742 ms 211584 KB Output is correct
17 Correct 748 ms 211612 KB Output is correct
18 Correct 749 ms 211484 KB Output is correct
19 Correct 746 ms 211584 KB Output is correct
20 Correct 745 ms 211604 KB Output is correct
21 Correct 741 ms 211628 KB Output is correct
22 Correct 749 ms 211348 KB Output is correct
23 Correct 742 ms 211384 KB Output is correct
24 Correct 746 ms 211480 KB Output is correct
25 Correct 753 ms 211528 KB Output is correct
26 Correct 747 ms 211504 KB Output is correct
27 Correct 742 ms 211512 KB Output is correct
28 Correct 745 ms 211416 KB Output is correct
29 Correct 748 ms 211424 KB Output is correct
30 Correct 749 ms 211380 KB Output is correct
31 Correct 750 ms 211384 KB Output is correct
32 Correct 746 ms 211404 KB Output is correct
33 Correct 746 ms 211508 KB Output is correct
34 Correct 849 ms 211404 KB Output is correct
35 Correct 741 ms 211604 KB Output is correct
36 Correct 744 ms 211492 KB Output is correct
37 Correct 744 ms 211416 KB Output is correct
38 Correct 753 ms 211564 KB Output is correct
39 Correct 749 ms 211520 KB Output is correct
40 Correct 744 ms 211524 KB Output is correct
41 Correct 748 ms 211548 KB Output is correct
42 Correct 748 ms 211376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 749 ms 211580 KB Output is correct
2 Correct 773 ms 211616 KB Output is correct
3 Correct 762 ms 211536 KB Output is correct
4 Correct 758 ms 211632 KB Output is correct
5 Correct 743 ms 211632 KB Output is correct
6 Correct 739 ms 211780 KB Output is correct
7 Correct 768 ms 211488 KB Output is correct
8 Correct 747 ms 211536 KB Output is correct
9 Correct 750 ms 211680 KB Output is correct
10 Correct 747 ms 211648 KB Output is correct
11 Correct 741 ms 211776 KB Output is correct
12 Correct 745 ms 211736 KB Output is correct
13 Correct 744 ms 211644 KB Output is correct
14 Correct 741 ms 211532 KB Output is correct
15 Correct 743 ms 211560 KB Output is correct
16 Correct 742 ms 211584 KB Output is correct
17 Correct 748 ms 211612 KB Output is correct
18 Correct 749 ms 211484 KB Output is correct
19 Correct 746 ms 211584 KB Output is correct
20 Correct 745 ms 211604 KB Output is correct
21 Correct 741 ms 211628 KB Output is correct
22 Correct 749 ms 211348 KB Output is correct
23 Correct 742 ms 211384 KB Output is correct
24 Correct 746 ms 211480 KB Output is correct
25 Correct 753 ms 211528 KB Output is correct
26 Correct 747 ms 211504 KB Output is correct
27 Correct 742 ms 211512 KB Output is correct
28 Correct 745 ms 211416 KB Output is correct
29 Correct 748 ms 211424 KB Output is correct
30 Correct 749 ms 211380 KB Output is correct
31 Correct 750 ms 211384 KB Output is correct
32 Correct 746 ms 211404 KB Output is correct
33 Correct 746 ms 211508 KB Output is correct
34 Correct 849 ms 211404 KB Output is correct
35 Correct 741 ms 211604 KB Output is correct
36 Correct 744 ms 211492 KB Output is correct
37 Correct 744 ms 211416 KB Output is correct
38 Correct 753 ms 211564 KB Output is correct
39 Correct 749 ms 211520 KB Output is correct
40 Correct 744 ms 211524 KB Output is correct
41 Correct 748 ms 211548 KB Output is correct
42 Correct 748 ms 211376 KB Output is correct
43 Correct 770 ms 211376 KB Output is correct
44 Correct 761 ms 211392 KB Output is correct
45 Correct 756 ms 211384 KB Output is correct
46 Correct 752 ms 211380 KB Output is correct
47 Correct 760 ms 211572 KB Output is correct
48 Correct 758 ms 211868 KB Output is correct
49 Correct 757 ms 211772 KB Output is correct
50 Correct 762 ms 211864 KB Output is correct
51 Correct 767 ms 211640 KB Output is correct
52 Correct 757 ms 211324 KB Output is correct
53 Correct 755 ms 211316 KB Output is correct
54 Correct 757 ms 211644 KB Output is correct
55 Correct 762 ms 211828 KB Output is correct
56 Correct 763 ms 211424 KB Output is correct
57 Correct 767 ms 211572 KB Output is correct
58 Correct 763 ms 211732 KB Output is correct
59 Correct 766 ms 211756 KB Output is correct
60 Correct 761 ms 211664 KB Output is correct
61 Correct 758 ms 211384 KB Output is correct
62 Correct 767 ms 211648 KB Output is correct
63 Correct 757 ms 211648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 749 ms 211580 KB Output is correct
2 Correct 773 ms 211616 KB Output is correct
3 Correct 762 ms 211536 KB Output is correct
4 Correct 758 ms 211632 KB Output is correct
5 Correct 743 ms 211632 KB Output is correct
6 Correct 739 ms 211780 KB Output is correct
7 Correct 768 ms 211488 KB Output is correct
8 Correct 747 ms 211536 KB Output is correct
9 Correct 750 ms 211680 KB Output is correct
10 Correct 747 ms 211648 KB Output is correct
11 Correct 741 ms 211776 KB Output is correct
12 Correct 745 ms 211736 KB Output is correct
13 Correct 744 ms 211644 KB Output is correct
14 Correct 741 ms 211532 KB Output is correct
15 Correct 743 ms 211560 KB Output is correct
16 Correct 742 ms 211584 KB Output is correct
17 Correct 748 ms 211612 KB Output is correct
18 Correct 749 ms 211484 KB Output is correct
19 Correct 746 ms 211584 KB Output is correct
20 Correct 745 ms 211604 KB Output is correct
21 Correct 741 ms 211628 KB Output is correct
22 Correct 749 ms 211348 KB Output is correct
23 Correct 742 ms 211384 KB Output is correct
24 Correct 746 ms 211480 KB Output is correct
25 Correct 753 ms 211528 KB Output is correct
26 Correct 747 ms 211504 KB Output is correct
27 Correct 742 ms 211512 KB Output is correct
28 Correct 745 ms 211416 KB Output is correct
29 Correct 748 ms 211424 KB Output is correct
30 Correct 749 ms 211380 KB Output is correct
31 Correct 750 ms 211384 KB Output is correct
32 Correct 746 ms 211404 KB Output is correct
33 Correct 746 ms 211508 KB Output is correct
34 Correct 849 ms 211404 KB Output is correct
35 Correct 741 ms 211604 KB Output is correct
36 Correct 744 ms 211492 KB Output is correct
37 Correct 744 ms 211416 KB Output is correct
38 Correct 753 ms 211564 KB Output is correct
39 Correct 749 ms 211520 KB Output is correct
40 Correct 744 ms 211524 KB Output is correct
41 Correct 748 ms 211548 KB Output is correct
42 Correct 748 ms 211376 KB Output is correct
43 Correct 770 ms 211376 KB Output is correct
44 Correct 761 ms 211392 KB Output is correct
45 Correct 756 ms 211384 KB Output is correct
46 Correct 752 ms 211380 KB Output is correct
47 Correct 760 ms 211572 KB Output is correct
48 Correct 758 ms 211868 KB Output is correct
49 Correct 757 ms 211772 KB Output is correct
50 Correct 762 ms 211864 KB Output is correct
51 Correct 767 ms 211640 KB Output is correct
52 Correct 757 ms 211324 KB Output is correct
53 Correct 755 ms 211316 KB Output is correct
54 Correct 757 ms 211644 KB Output is correct
55 Correct 762 ms 211828 KB Output is correct
56 Correct 763 ms 211424 KB Output is correct
57 Correct 767 ms 211572 KB Output is correct
58 Correct 763 ms 211732 KB Output is correct
59 Correct 766 ms 211756 KB Output is correct
60 Correct 761 ms 211664 KB Output is correct
61 Correct 758 ms 211384 KB Output is correct
62 Correct 767 ms 211648 KB Output is correct
63 Correct 757 ms 211648 KB Output is correct
64 Runtime error 933 ms 428928 KB Execution killed with signal 11
65 Halted 0 ms 0 KB -