Submission #898870

# Submission time Handle Problem Language Result Execution time Memory
898870 2024-01-05T08:21:48 Z arashMLG Cubeword (CEOI19_cubeword) C++17
84 / 100
499 ms 16196 KB
#include<bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse4")

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

const int N = 5e5 + 23;
const int K = 26 + 26;
const ll mod = 998244353;
const ll inf = 1e18;

//#define F         first
#define S         second
#define pb        push_back
#define sz(x)     ((int)x.size())
#define all(x)    x.begin(),x.end()
#define lc        (v<<1)
#define rc        ((v<<1)|1)
#define F(x)      for(int x = 0; x < K; x++)
#define debug(x)  cout<<#x << " : " << x << endl;
#define int       ll

int dp[K][K][K];
vector<string> s[11];
int cnt[K][K];
vector<pii> vec;
int val[300];
int javab = 0;

void solve(int len) {
	F(i) F(j) {
		cnt[i][j] = 0;
		F(k) dp[i][j][k] = 0;
	}
	sort(all(s[len]));
	s[len].resize(unique(all(s[len])) - s[len].begin());
	for(string t : s[len]) {
		cnt[val[t[0]]][val[t.back()]] ++;
	}
	F(i) F(a) F(b) F(c) {
		(dp[a][b][c] += (1LL*cnt[i][a]*cnt[i][b]%mod*cnt[i][c] %mod)) %= mod;
	}
	int ans=0;
	F(a) F(b) F(c) F(d) {
		(ans += (dp[a][b][c] *dp[a][b][d]%mod*dp[a][c][d]%mod*dp[b][c][d])) %= mod;
	}
	(javab += ans) %=mod;
}

int32_t main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	int x = 0;
	for(char c = 'a'; c<= 'z'; c++) {
		val[c] = x++;
	}
	for(char c = 'A'; c<= 'Z'; c++) {
		val[c] = x++;
	}
	for(char c = '0'; c <= '9'; c++) {
		val[c] = x ++;
	}
	int n; cin>>n;
	for(int i = 0 ;i < n ; i++){ 
		string t; cin>>t;
		s[sz(t)].pb(t);
		reverse(all(t));
		s[sz(t)].pb(t);
	}
	for(int i = 3; i <= 10; i ++) solve(i);
	cout<<javab%mod;
	return 0;
}

Compilation message

cubeword.cpp: In function 'void solve(ll)':
cubeword.cpp:42:15: warning: array subscript has type 'char' [-Wchar-subscripts]
   42 |   cnt[val[t[0]]][val[t.back()]] ++;
      |               ^
cubeword.cpp:42:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   42 |   cnt[val[t[0]]][val[t.back()]] ++;
      |                      ~~~~~~^~
cubeword.cpp: In function 'int32_t main()':
cubeword.cpp:58:7: warning: array subscript has type 'char' [-Wchar-subscripts]
   58 |   val[c] = x++;
      |       ^
cubeword.cpp:61:7: warning: array subscript has type 'char' [-Wchar-subscripts]
   61 |   val[c] = x++;
      |       ^
cubeword.cpp:64:7: warning: array subscript has type 'char' [-Wchar-subscripts]
   64 |   val[c] = x ++;
      |       ^
# Verdict Execution time Memory Grader output
1 Correct 499 ms 8176 KB Output is correct
2 Correct 439 ms 8220 KB Output is correct
3 Correct 435 ms 8152 KB Output is correct
4 Correct 454 ms 8268 KB Output is correct
5 Correct 441 ms 8252 KB Output is correct
6 Correct 444 ms 8392 KB Output is correct
7 Correct 445 ms 8436 KB Output is correct
8 Correct 433 ms 8152 KB Output is correct
9 Correct 441 ms 8212 KB Output is correct
10 Correct 439 ms 8228 KB Output is correct
11 Correct 439 ms 8328 KB Output is correct
12 Correct 432 ms 8252 KB Output is correct
13 Correct 440 ms 8252 KB Output is correct
14 Correct 432 ms 8092 KB Output is correct
15 Correct 433 ms 8192 KB Output is correct
16 Correct 435 ms 8068 KB Output is correct
17 Correct 438 ms 8420 KB Output is correct
18 Correct 439 ms 8104 KB Output is correct
19 Correct 440 ms 8192 KB Output is correct
20 Correct 432 ms 8168 KB Output is correct
21 Correct 435 ms 8240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 499 ms 8176 KB Output is correct
2 Correct 439 ms 8220 KB Output is correct
3 Correct 435 ms 8152 KB Output is correct
4 Correct 454 ms 8268 KB Output is correct
5 Correct 441 ms 8252 KB Output is correct
6 Correct 444 ms 8392 KB Output is correct
7 Correct 445 ms 8436 KB Output is correct
8 Correct 433 ms 8152 KB Output is correct
9 Correct 441 ms 8212 KB Output is correct
10 Correct 439 ms 8228 KB Output is correct
11 Correct 439 ms 8328 KB Output is correct
12 Correct 432 ms 8252 KB Output is correct
13 Correct 440 ms 8252 KB Output is correct
14 Correct 432 ms 8092 KB Output is correct
15 Correct 433 ms 8192 KB Output is correct
16 Correct 435 ms 8068 KB Output is correct
17 Correct 438 ms 8420 KB Output is correct
18 Correct 439 ms 8104 KB Output is correct
19 Correct 440 ms 8192 KB Output is correct
20 Correct 432 ms 8168 KB Output is correct
21 Correct 435 ms 8240 KB Output is correct
22 Correct 430 ms 7904 KB Output is correct
23 Correct 432 ms 7976 KB Output is correct
24 Correct 441 ms 8156 KB Output is correct
25 Correct 432 ms 7952 KB Output is correct
26 Correct 435 ms 7872 KB Output is correct
27 Correct 431 ms 8228 KB Output is correct
28 Correct 435 ms 7996 KB Output is correct
29 Correct 433 ms 7868 KB Output is correct
30 Correct 441 ms 8000 KB Output is correct
31 Correct 434 ms 7996 KB Output is correct
32 Correct 431 ms 7988 KB Output is correct
33 Correct 441 ms 7876 KB Output is correct
34 Correct 431 ms 8092 KB Output is correct
35 Correct 437 ms 8224 KB Output is correct
36 Correct 434 ms 8092 KB Output is correct
37 Correct 430 ms 7996 KB Output is correct
38 Correct 434 ms 8192 KB Output is correct
39 Correct 430 ms 8116 KB Output is correct
40 Correct 436 ms 8060 KB Output is correct
41 Correct 430 ms 8172 KB Output is correct
42 Correct 435 ms 7992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 499 ms 8176 KB Output is correct
2 Correct 439 ms 8220 KB Output is correct
3 Correct 435 ms 8152 KB Output is correct
4 Correct 454 ms 8268 KB Output is correct
5 Correct 441 ms 8252 KB Output is correct
6 Correct 444 ms 8392 KB Output is correct
7 Correct 445 ms 8436 KB Output is correct
8 Correct 433 ms 8152 KB Output is correct
9 Correct 441 ms 8212 KB Output is correct
10 Correct 439 ms 8228 KB Output is correct
11 Correct 439 ms 8328 KB Output is correct
12 Correct 432 ms 8252 KB Output is correct
13 Correct 440 ms 8252 KB Output is correct
14 Correct 432 ms 8092 KB Output is correct
15 Correct 433 ms 8192 KB Output is correct
16 Correct 435 ms 8068 KB Output is correct
17 Correct 438 ms 8420 KB Output is correct
18 Correct 439 ms 8104 KB Output is correct
19 Correct 440 ms 8192 KB Output is correct
20 Correct 432 ms 8168 KB Output is correct
21 Correct 435 ms 8240 KB Output is correct
22 Correct 430 ms 7904 KB Output is correct
23 Correct 432 ms 7976 KB Output is correct
24 Correct 441 ms 8156 KB Output is correct
25 Correct 432 ms 7952 KB Output is correct
26 Correct 435 ms 7872 KB Output is correct
27 Correct 431 ms 8228 KB Output is correct
28 Correct 435 ms 7996 KB Output is correct
29 Correct 433 ms 7868 KB Output is correct
30 Correct 441 ms 8000 KB Output is correct
31 Correct 434 ms 7996 KB Output is correct
32 Correct 431 ms 7988 KB Output is correct
33 Correct 441 ms 7876 KB Output is correct
34 Correct 431 ms 8092 KB Output is correct
35 Correct 437 ms 8224 KB Output is correct
36 Correct 434 ms 8092 KB Output is correct
37 Correct 430 ms 7996 KB Output is correct
38 Correct 434 ms 8192 KB Output is correct
39 Correct 430 ms 8116 KB Output is correct
40 Correct 436 ms 8060 KB Output is correct
41 Correct 430 ms 8172 KB Output is correct
42 Correct 435 ms 7992 KB Output is correct
43 Correct 437 ms 7876 KB Output is correct
44 Correct 432 ms 7960 KB Output is correct
45 Correct 435 ms 8104 KB Output is correct
46 Correct 439 ms 7956 KB Output is correct
47 Correct 434 ms 8032 KB Output is correct
48 Correct 430 ms 8352 KB Output is correct
49 Correct 433 ms 8768 KB Output is correct
50 Correct 433 ms 8392 KB Output is correct
51 Correct 431 ms 8244 KB Output is correct
52 Correct 434 ms 7956 KB Output is correct
53 Correct 433 ms 7824 KB Output is correct
54 Correct 435 ms 8332 KB Output is correct
55 Correct 431 ms 8212 KB Output is correct
56 Correct 431 ms 7924 KB Output is correct
57 Correct 435 ms 8268 KB Output is correct
58 Correct 431 ms 8376 KB Output is correct
59 Correct 434 ms 8272 KB Output is correct
60 Correct 436 ms 8252 KB Output is correct
61 Correct 459 ms 8012 KB Output is correct
62 Correct 436 ms 8216 KB Output is correct
63 Correct 438 ms 8624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 499 ms 8176 KB Output is correct
2 Correct 439 ms 8220 KB Output is correct
3 Correct 435 ms 8152 KB Output is correct
4 Correct 454 ms 8268 KB Output is correct
5 Correct 441 ms 8252 KB Output is correct
6 Correct 444 ms 8392 KB Output is correct
7 Correct 445 ms 8436 KB Output is correct
8 Correct 433 ms 8152 KB Output is correct
9 Correct 441 ms 8212 KB Output is correct
10 Correct 439 ms 8228 KB Output is correct
11 Correct 439 ms 8328 KB Output is correct
12 Correct 432 ms 8252 KB Output is correct
13 Correct 440 ms 8252 KB Output is correct
14 Correct 432 ms 8092 KB Output is correct
15 Correct 433 ms 8192 KB Output is correct
16 Correct 435 ms 8068 KB Output is correct
17 Correct 438 ms 8420 KB Output is correct
18 Correct 439 ms 8104 KB Output is correct
19 Correct 440 ms 8192 KB Output is correct
20 Correct 432 ms 8168 KB Output is correct
21 Correct 435 ms 8240 KB Output is correct
22 Correct 430 ms 7904 KB Output is correct
23 Correct 432 ms 7976 KB Output is correct
24 Correct 441 ms 8156 KB Output is correct
25 Correct 432 ms 7952 KB Output is correct
26 Correct 435 ms 7872 KB Output is correct
27 Correct 431 ms 8228 KB Output is correct
28 Correct 435 ms 7996 KB Output is correct
29 Correct 433 ms 7868 KB Output is correct
30 Correct 441 ms 8000 KB Output is correct
31 Correct 434 ms 7996 KB Output is correct
32 Correct 431 ms 7988 KB Output is correct
33 Correct 441 ms 7876 KB Output is correct
34 Correct 431 ms 8092 KB Output is correct
35 Correct 437 ms 8224 KB Output is correct
36 Correct 434 ms 8092 KB Output is correct
37 Correct 430 ms 7996 KB Output is correct
38 Correct 434 ms 8192 KB Output is correct
39 Correct 430 ms 8116 KB Output is correct
40 Correct 436 ms 8060 KB Output is correct
41 Correct 430 ms 8172 KB Output is correct
42 Correct 435 ms 7992 KB Output is correct
43 Correct 437 ms 7876 KB Output is correct
44 Correct 432 ms 7960 KB Output is correct
45 Correct 435 ms 8104 KB Output is correct
46 Correct 439 ms 7956 KB Output is correct
47 Correct 434 ms 8032 KB Output is correct
48 Correct 430 ms 8352 KB Output is correct
49 Correct 433 ms 8768 KB Output is correct
50 Correct 433 ms 8392 KB Output is correct
51 Correct 431 ms 8244 KB Output is correct
52 Correct 434 ms 7956 KB Output is correct
53 Correct 433 ms 7824 KB Output is correct
54 Correct 435 ms 8332 KB Output is correct
55 Correct 431 ms 8212 KB Output is correct
56 Correct 431 ms 7924 KB Output is correct
57 Correct 435 ms 8268 KB Output is correct
58 Correct 431 ms 8376 KB Output is correct
59 Correct 434 ms 8272 KB Output is correct
60 Correct 436 ms 8252 KB Output is correct
61 Correct 459 ms 8012 KB Output is correct
62 Correct 436 ms 8216 KB Output is correct
63 Correct 438 ms 8624 KB Output is correct
64 Runtime error 74 ms 16196 KB Execution killed with signal 11
65 Halted 0 ms 0 KB -