Submission #945559

# Submission time Handle Problem Language Result Execution time Memory
945559 2024-03-14T04:39:33 Z Minbaev Cubeword (CEOI19_cubeword) C++17
50 / 100
406 ms 15988 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(x) x.begin(),x.end()
#define pb push_back

const int N=1e6 + 5	;
const int inf = 1e18 + 7;
const int mod = 998244353;

int g[11][25][25];
int ans = 0;
int n,m,k;

vector<int>vs;

void dfs(int i){
	
	if(i == 4){
		
		for(int sz = 3;sz<=10;sz++){
			int val = 1;
				for(int j = 0;j<4;j++){
					int sum = 0; 
					for(int k = 0;k<='p'-'a';k++){
						int c = 1;
						
						for(int l = 0;l<4;l++){
							if(l == j)continue;
							c *= g[sz][vs[l]][k];
						}
						sum += c;
						sum %= mod;
					}
					val *= sum;
					val %= mod;
				}
			ans += val;
			ans %= mod;
		}
		return;
	}
	
	for(int l = 0;l<='p'-'a';l++){
		vs.pb(l);
		dfs(i + 1);
		vs.pop_back();
	}
	
}


void solve(){
	
	cin >> n;
	map<string,int>mp;
	for(int i = 1;i<=n;i++){
		string a;
		cin >> a;
		if(mp[a] == 0)
		g[a.size()][a[0]-'a'][a[a.size()-1]-'a'] += 1;
		
		mp[a] += 1;
		
		reverse(all(a));
		if(mp[a] == 0){
			g[a.size()][a[0]-'a'][a[a.size()-1]-'a'] += 1;
		}
		mp[a] += 1;
	}
	
	dfs(0);
	cout << ans << '\n';
	
}
/*

*/
signed main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int tt=1;//cin>>tt>>n;
	while(tt--)solve();

}

# Verdict Execution time Memory Grader output
1 Correct 312 ms 15048 KB Output is correct
2 Correct 281 ms 14932 KB Output is correct
3 Correct 287 ms 14740 KB Output is correct
4 Correct 298 ms 14948 KB Output is correct
5 Correct 286 ms 14932 KB Output is correct
6 Correct 292 ms 14928 KB Output is correct
7 Correct 293 ms 14936 KB Output is correct
8 Correct 406 ms 14964 KB Output is correct
9 Correct 300 ms 14748 KB Output is correct
10 Correct 307 ms 15188 KB Output is correct
11 Correct 280 ms 14956 KB Output is correct
12 Correct 315 ms 14896 KB Output is correct
13 Correct 300 ms 14972 KB Output is correct
14 Correct 303 ms 14964 KB Output is correct
15 Correct 287 ms 15000 KB Output is correct
16 Correct 302 ms 14932 KB Output is correct
17 Correct 303 ms 14960 KB Output is correct
18 Correct 300 ms 14756 KB Output is correct
19 Correct 281 ms 14948 KB Output is correct
20 Correct 294 ms 15276 KB Output is correct
21 Correct 306 ms 14740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 312 ms 15048 KB Output is correct
2 Correct 281 ms 14932 KB Output is correct
3 Correct 287 ms 14740 KB Output is correct
4 Correct 298 ms 14948 KB Output is correct
5 Correct 286 ms 14932 KB Output is correct
6 Correct 292 ms 14928 KB Output is correct
7 Correct 293 ms 14936 KB Output is correct
8 Correct 406 ms 14964 KB Output is correct
9 Correct 300 ms 14748 KB Output is correct
10 Correct 307 ms 15188 KB Output is correct
11 Correct 280 ms 14956 KB Output is correct
12 Correct 315 ms 14896 KB Output is correct
13 Correct 300 ms 14972 KB Output is correct
14 Correct 303 ms 14964 KB Output is correct
15 Correct 287 ms 15000 KB Output is correct
16 Correct 302 ms 14932 KB Output is correct
17 Correct 303 ms 14960 KB Output is correct
18 Correct 300 ms 14756 KB Output is correct
19 Correct 281 ms 14948 KB Output is correct
20 Correct 294 ms 15276 KB Output is correct
21 Correct 306 ms 14740 KB Output is correct
22 Correct 301 ms 15700 KB Output is correct
23 Correct 304 ms 15620 KB Output is correct
24 Correct 305 ms 15632 KB Output is correct
25 Correct 310 ms 15612 KB Output is correct
26 Correct 291 ms 15412 KB Output is correct
27 Correct 301 ms 15504 KB Output is correct
28 Correct 290 ms 15572 KB Output is correct
29 Correct 305 ms 15624 KB Output is correct
30 Correct 288 ms 15440 KB Output is correct
31 Correct 281 ms 15440 KB Output is correct
32 Correct 292 ms 15444 KB Output is correct
33 Correct 282 ms 15440 KB Output is correct
34 Correct 291 ms 15988 KB Output is correct
35 Correct 291 ms 15652 KB Output is correct
36 Correct 285 ms 15400 KB Output is correct
37 Correct 283 ms 15444 KB Output is correct
38 Correct 289 ms 15440 KB Output is correct
39 Correct 330 ms 15864 KB Output is correct
40 Correct 284 ms 15444 KB Output is correct
41 Correct 308 ms 15620 KB Output is correct
42 Correct 285 ms 15620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 312 ms 15048 KB Output is correct
2 Correct 281 ms 14932 KB Output is correct
3 Correct 287 ms 14740 KB Output is correct
4 Correct 298 ms 14948 KB Output is correct
5 Correct 286 ms 14932 KB Output is correct
6 Correct 292 ms 14928 KB Output is correct
7 Correct 293 ms 14936 KB Output is correct
8 Correct 406 ms 14964 KB Output is correct
9 Correct 300 ms 14748 KB Output is correct
10 Correct 307 ms 15188 KB Output is correct
11 Correct 280 ms 14956 KB Output is correct
12 Correct 315 ms 14896 KB Output is correct
13 Correct 300 ms 14972 KB Output is correct
14 Correct 303 ms 14964 KB Output is correct
15 Correct 287 ms 15000 KB Output is correct
16 Correct 302 ms 14932 KB Output is correct
17 Correct 303 ms 14960 KB Output is correct
18 Correct 300 ms 14756 KB Output is correct
19 Correct 281 ms 14948 KB Output is correct
20 Correct 294 ms 15276 KB Output is correct
21 Correct 306 ms 14740 KB Output is correct
22 Correct 301 ms 15700 KB Output is correct
23 Correct 304 ms 15620 KB Output is correct
24 Correct 305 ms 15632 KB Output is correct
25 Correct 310 ms 15612 KB Output is correct
26 Correct 291 ms 15412 KB Output is correct
27 Correct 301 ms 15504 KB Output is correct
28 Correct 290 ms 15572 KB Output is correct
29 Correct 305 ms 15624 KB Output is correct
30 Correct 288 ms 15440 KB Output is correct
31 Correct 281 ms 15440 KB Output is correct
32 Correct 292 ms 15444 KB Output is correct
33 Correct 282 ms 15440 KB Output is correct
34 Correct 291 ms 15988 KB Output is correct
35 Correct 291 ms 15652 KB Output is correct
36 Correct 285 ms 15400 KB Output is correct
37 Correct 283 ms 15444 KB Output is correct
38 Correct 289 ms 15440 KB Output is correct
39 Correct 330 ms 15864 KB Output is correct
40 Correct 284 ms 15444 KB Output is correct
41 Correct 308 ms 15620 KB Output is correct
42 Correct 285 ms 15620 KB Output is correct
43 Incorrect 280 ms 15844 KB Output isn't correct
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 312 ms 15048 KB Output is correct
2 Correct 281 ms 14932 KB Output is correct
3 Correct 287 ms 14740 KB Output is correct
4 Correct 298 ms 14948 KB Output is correct
5 Correct 286 ms 14932 KB Output is correct
6 Correct 292 ms 14928 KB Output is correct
7 Correct 293 ms 14936 KB Output is correct
8 Correct 406 ms 14964 KB Output is correct
9 Correct 300 ms 14748 KB Output is correct
10 Correct 307 ms 15188 KB Output is correct
11 Correct 280 ms 14956 KB Output is correct
12 Correct 315 ms 14896 KB Output is correct
13 Correct 300 ms 14972 KB Output is correct
14 Correct 303 ms 14964 KB Output is correct
15 Correct 287 ms 15000 KB Output is correct
16 Correct 302 ms 14932 KB Output is correct
17 Correct 303 ms 14960 KB Output is correct
18 Correct 300 ms 14756 KB Output is correct
19 Correct 281 ms 14948 KB Output is correct
20 Correct 294 ms 15276 KB Output is correct
21 Correct 306 ms 14740 KB Output is correct
22 Correct 301 ms 15700 KB Output is correct
23 Correct 304 ms 15620 KB Output is correct
24 Correct 305 ms 15632 KB Output is correct
25 Correct 310 ms 15612 KB Output is correct
26 Correct 291 ms 15412 KB Output is correct
27 Correct 301 ms 15504 KB Output is correct
28 Correct 290 ms 15572 KB Output is correct
29 Correct 305 ms 15624 KB Output is correct
30 Correct 288 ms 15440 KB Output is correct
31 Correct 281 ms 15440 KB Output is correct
32 Correct 292 ms 15444 KB Output is correct
33 Correct 282 ms 15440 KB Output is correct
34 Correct 291 ms 15988 KB Output is correct
35 Correct 291 ms 15652 KB Output is correct
36 Correct 285 ms 15400 KB Output is correct
37 Correct 283 ms 15444 KB Output is correct
38 Correct 289 ms 15440 KB Output is correct
39 Correct 330 ms 15864 KB Output is correct
40 Correct 284 ms 15444 KB Output is correct
41 Correct 308 ms 15620 KB Output is correct
42 Correct 285 ms 15620 KB Output is correct
43 Incorrect 280 ms 15844 KB Output isn't correct
44 Halted 0 ms 0 KB -