Submission #578905

# Submission time Handle Problem Language Result Execution time Memory
578905 2022-06-18T07:36:39 Z amunduzbaev Cubeword (CEOI19_cubeword) C++17
100 / 100
563 ms 47216 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
typedef int64_t ll;
#define int ll

const int N = 1e5 + 5;
const int M = 62;
const int mod = 119 << 23 | 1;
int is[M][M], pre[M][M][M], cnt[M][M][M][M];

int bp(int a, int b){
	int c=1;
	while(b){
		if(b&1) c = c * 1ll * a % mod;
		a = a * 1ll * a % mod, b >>= 1;
	} return c;
}

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n;
	vector<string> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		for(auto& x : a[i]){
			if('a' <= x && x <= 'z') x = x - 'a';
			else if('A' <= x && x <= 'Z') x = x - 'A' + 26;
			else if('0' <= x && x <= '9') x = x - '0' + 52;
		}
		
		string b = a[i];
		reverse(b.begin(), b.end());
		a.push_back(b);
	}
	int p[4] {};
	for(int i=0;i<M;i++){
		for(int j=0;j<M;j++){
			for(int k=0;k<M;k++){
				for(int l=0;l<M;l++){
					p[0] = i, p[1] = j, p[2] = k, p[3] = l; // = {i, j, k, l};
					sort(p, p + 4);
					cnt[p[0]][p[1]][p[2]][p[3]]++;
				}
			}
		}
	}
	
	sort(a.begin(), a.end());
	vector<string> b;
	for(int i=0;i<n*2;i++){
		if(!i || a[i] != a[i-1]) b.push_back(a[i]);
	}
	swap(a, b);
	sort(a.begin(), a.end(), [&](string& a, string& b){
		return a.size() < b.size();
	});
	n = a.size();
	
	
	int l = 0, tot = 0;
	for(int s=3;s<=10;s++){
		memset(is, 0, sizeof is);
		int k = l;
		while(l < n && (int)a[l].size() == s){
			is[a[l][0]][a[l][s-1]]++;
			l++;
		}
		if(l == k) continue;
		memset(pre, 0, sizeof pre);
		
		for(int i=0;i<M;i++){
			for(int j=i;j<M;j++){
				for(int k=j;k<M;k++){
					for(int l=0;l<M;l++){
						pre[i][j][k] = (pre[i][j][k] + is[i][l] * 1ll * is[j][l] % mod * is[k][l]) % mod;
					}
				}
			}
		}
		
		for(int i=0;i<M;i++){
			for(int j=i;j<M;j++){
				for(int k=j;k<M;k++){
					for(int l=k;l<M;l++){
						int res = cnt[i][j][k][l] * 1ll * pre[i][j][k] % mod;
						res = res * 1ll * pre[i][j][l] % mod;
						res = res * 1ll * pre[i][k][l] % mod;
						res = res * 1ll * pre[j][k][l] % mod;
						tot += res;
						if(tot >= mod) tot -= mod;
					}
				}
			}
		}
	}
	
	//~ cout<<tot<<"\n";
	//~ tot = tot * 1ll * bp(6, mod - 2) % mod;
	cout<<tot<<"\n";
}
 

Compilation message

cubeword.cpp: In function 'int main()':
cubeword.cpp:68:14: warning: array subscript has type 'char' [-Wchar-subscripts]
   68 |    is[a[l][0]][a[l][s-1]]++;
      |              ^
cubeword.cpp:68:25: warning: array subscript has type 'char' [-Wchar-subscripts]
   68 |    is[a[l][0]][a[l][s-1]]++;
      |                         ^
# Verdict Execution time Memory Grader output
1 Correct 551 ms 46352 KB Output is correct
2 Correct 543 ms 46412 KB Output is correct
3 Correct 553 ms 46612 KB Output is correct
4 Correct 546 ms 46416 KB Output is correct
5 Correct 532 ms 46320 KB Output is correct
6 Correct 530 ms 46424 KB Output is correct
7 Correct 547 ms 46388 KB Output is correct
8 Correct 546 ms 46388 KB Output is correct
9 Correct 525 ms 46456 KB Output is correct
10 Correct 536 ms 46308 KB Output is correct
11 Correct 530 ms 46316 KB Output is correct
12 Correct 542 ms 46320 KB Output is correct
13 Correct 531 ms 46316 KB Output is correct
14 Correct 525 ms 46304 KB Output is correct
15 Correct 533 ms 46368 KB Output is correct
16 Correct 523 ms 46384 KB Output is correct
17 Correct 528 ms 46408 KB Output is correct
18 Correct 538 ms 46308 KB Output is correct
19 Correct 537 ms 46384 KB Output is correct
20 Correct 522 ms 46344 KB Output is correct
21 Correct 526 ms 46400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 551 ms 46352 KB Output is correct
2 Correct 543 ms 46412 KB Output is correct
3 Correct 553 ms 46612 KB Output is correct
4 Correct 546 ms 46416 KB Output is correct
5 Correct 532 ms 46320 KB Output is correct
6 Correct 530 ms 46424 KB Output is correct
7 Correct 547 ms 46388 KB Output is correct
8 Correct 546 ms 46388 KB Output is correct
9 Correct 525 ms 46456 KB Output is correct
10 Correct 536 ms 46308 KB Output is correct
11 Correct 530 ms 46316 KB Output is correct
12 Correct 542 ms 46320 KB Output is correct
13 Correct 531 ms 46316 KB Output is correct
14 Correct 525 ms 46304 KB Output is correct
15 Correct 533 ms 46368 KB Output is correct
16 Correct 523 ms 46384 KB Output is correct
17 Correct 528 ms 46408 KB Output is correct
18 Correct 538 ms 46308 KB Output is correct
19 Correct 537 ms 46384 KB Output is correct
20 Correct 522 ms 46344 KB Output is correct
21 Correct 526 ms 46400 KB Output is correct
22 Correct 536 ms 46352 KB Output is correct
23 Correct 536 ms 46348 KB Output is correct
24 Correct 529 ms 46368 KB Output is correct
25 Correct 526 ms 46476 KB Output is correct
26 Correct 523 ms 46384 KB Output is correct
27 Correct 527 ms 46392 KB Output is correct
28 Correct 541 ms 46324 KB Output is correct
29 Correct 536 ms 46364 KB Output is correct
30 Correct 531 ms 46420 KB Output is correct
31 Correct 530 ms 46320 KB Output is correct
32 Correct 544 ms 46384 KB Output is correct
33 Correct 538 ms 46368 KB Output is correct
34 Correct 529 ms 46384 KB Output is correct
35 Correct 537 ms 46296 KB Output is correct
36 Correct 523 ms 46424 KB Output is correct
37 Correct 550 ms 46424 KB Output is correct
38 Correct 522 ms 46396 KB Output is correct
39 Correct 520 ms 46396 KB Output is correct
40 Correct 536 ms 46380 KB Output is correct
41 Correct 528 ms 46428 KB Output is correct
42 Correct 523 ms 46400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 551 ms 46352 KB Output is correct
2 Correct 543 ms 46412 KB Output is correct
3 Correct 553 ms 46612 KB Output is correct
4 Correct 546 ms 46416 KB Output is correct
5 Correct 532 ms 46320 KB Output is correct
6 Correct 530 ms 46424 KB Output is correct
7 Correct 547 ms 46388 KB Output is correct
8 Correct 546 ms 46388 KB Output is correct
9 Correct 525 ms 46456 KB Output is correct
10 Correct 536 ms 46308 KB Output is correct
11 Correct 530 ms 46316 KB Output is correct
12 Correct 542 ms 46320 KB Output is correct
13 Correct 531 ms 46316 KB Output is correct
14 Correct 525 ms 46304 KB Output is correct
15 Correct 533 ms 46368 KB Output is correct
16 Correct 523 ms 46384 KB Output is correct
17 Correct 528 ms 46408 KB Output is correct
18 Correct 538 ms 46308 KB Output is correct
19 Correct 537 ms 46384 KB Output is correct
20 Correct 522 ms 46344 KB Output is correct
21 Correct 526 ms 46400 KB Output is correct
22 Correct 536 ms 46352 KB Output is correct
23 Correct 536 ms 46348 KB Output is correct
24 Correct 529 ms 46368 KB Output is correct
25 Correct 526 ms 46476 KB Output is correct
26 Correct 523 ms 46384 KB Output is correct
27 Correct 527 ms 46392 KB Output is correct
28 Correct 541 ms 46324 KB Output is correct
29 Correct 536 ms 46364 KB Output is correct
30 Correct 531 ms 46420 KB Output is correct
31 Correct 530 ms 46320 KB Output is correct
32 Correct 544 ms 46384 KB Output is correct
33 Correct 538 ms 46368 KB Output is correct
34 Correct 529 ms 46384 KB Output is correct
35 Correct 537 ms 46296 KB Output is correct
36 Correct 523 ms 46424 KB Output is correct
37 Correct 550 ms 46424 KB Output is correct
38 Correct 522 ms 46396 KB Output is correct
39 Correct 520 ms 46396 KB Output is correct
40 Correct 536 ms 46380 KB Output is correct
41 Correct 528 ms 46428 KB Output is correct
42 Correct 523 ms 46400 KB Output is correct
43 Correct 525 ms 46388 KB Output is correct
44 Correct 535 ms 46348 KB Output is correct
45 Correct 522 ms 46384 KB Output is correct
46 Correct 523 ms 46388 KB Output is correct
47 Correct 543 ms 46368 KB Output is correct
48 Correct 528 ms 46392 KB Output is correct
49 Correct 529 ms 46332 KB Output is correct
50 Correct 523 ms 46384 KB Output is correct
51 Correct 524 ms 46368 KB Output is correct
52 Correct 519 ms 46480 KB Output is correct
53 Correct 524 ms 46396 KB Output is correct
54 Correct 526 ms 46384 KB Output is correct
55 Correct 524 ms 46348 KB Output is correct
56 Correct 518 ms 46368 KB Output is correct
57 Correct 521 ms 46388 KB Output is correct
58 Correct 522 ms 46348 KB Output is correct
59 Correct 542 ms 46388 KB Output is correct
60 Correct 523 ms 46432 KB Output is correct
61 Correct 530 ms 46444 KB Output is correct
62 Correct 529 ms 46356 KB Output is correct
63 Correct 526 ms 46352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 551 ms 46352 KB Output is correct
2 Correct 543 ms 46412 KB Output is correct
3 Correct 553 ms 46612 KB Output is correct
4 Correct 546 ms 46416 KB Output is correct
5 Correct 532 ms 46320 KB Output is correct
6 Correct 530 ms 46424 KB Output is correct
7 Correct 547 ms 46388 KB Output is correct
8 Correct 546 ms 46388 KB Output is correct
9 Correct 525 ms 46456 KB Output is correct
10 Correct 536 ms 46308 KB Output is correct
11 Correct 530 ms 46316 KB Output is correct
12 Correct 542 ms 46320 KB Output is correct
13 Correct 531 ms 46316 KB Output is correct
14 Correct 525 ms 46304 KB Output is correct
15 Correct 533 ms 46368 KB Output is correct
16 Correct 523 ms 46384 KB Output is correct
17 Correct 528 ms 46408 KB Output is correct
18 Correct 538 ms 46308 KB Output is correct
19 Correct 537 ms 46384 KB Output is correct
20 Correct 522 ms 46344 KB Output is correct
21 Correct 526 ms 46400 KB Output is correct
22 Correct 536 ms 46352 KB Output is correct
23 Correct 536 ms 46348 KB Output is correct
24 Correct 529 ms 46368 KB Output is correct
25 Correct 526 ms 46476 KB Output is correct
26 Correct 523 ms 46384 KB Output is correct
27 Correct 527 ms 46392 KB Output is correct
28 Correct 541 ms 46324 KB Output is correct
29 Correct 536 ms 46364 KB Output is correct
30 Correct 531 ms 46420 KB Output is correct
31 Correct 530 ms 46320 KB Output is correct
32 Correct 544 ms 46384 KB Output is correct
33 Correct 538 ms 46368 KB Output is correct
34 Correct 529 ms 46384 KB Output is correct
35 Correct 537 ms 46296 KB Output is correct
36 Correct 523 ms 46424 KB Output is correct
37 Correct 550 ms 46424 KB Output is correct
38 Correct 522 ms 46396 KB Output is correct
39 Correct 520 ms 46396 KB Output is correct
40 Correct 536 ms 46380 KB Output is correct
41 Correct 528 ms 46428 KB Output is correct
42 Correct 523 ms 46400 KB Output is correct
43 Correct 525 ms 46388 KB Output is correct
44 Correct 535 ms 46348 KB Output is correct
45 Correct 522 ms 46384 KB Output is correct
46 Correct 523 ms 46388 KB Output is correct
47 Correct 543 ms 46368 KB Output is correct
48 Correct 528 ms 46392 KB Output is correct
49 Correct 529 ms 46332 KB Output is correct
50 Correct 523 ms 46384 KB Output is correct
51 Correct 524 ms 46368 KB Output is correct
52 Correct 519 ms 46480 KB Output is correct
53 Correct 524 ms 46396 KB Output is correct
54 Correct 526 ms 46384 KB Output is correct
55 Correct 524 ms 46348 KB Output is correct
56 Correct 518 ms 46368 KB Output is correct
57 Correct 521 ms 46388 KB Output is correct
58 Correct 522 ms 46348 KB Output is correct
59 Correct 542 ms 46388 KB Output is correct
60 Correct 523 ms 46432 KB Output is correct
61 Correct 530 ms 46444 KB Output is correct
62 Correct 529 ms 46356 KB Output is correct
63 Correct 526 ms 46352 KB Output is correct
64 Correct 530 ms 46364 KB Output is correct
65 Correct 528 ms 47076 KB Output is correct
66 Correct 536 ms 47044 KB Output is correct
67 Correct 530 ms 47216 KB Output is correct
68 Correct 525 ms 47120 KB Output is correct
69 Correct 541 ms 47180 KB Output is correct
70 Correct 532 ms 47144 KB Output is correct
71 Correct 526 ms 47136 KB Output is correct
72 Correct 527 ms 47120 KB Output is correct
73 Correct 549 ms 47120 KB Output is correct
74 Correct 550 ms 47116 KB Output is correct
75 Correct 528 ms 47112 KB Output is correct
76 Correct 526 ms 47132 KB Output is correct
77 Correct 533 ms 47168 KB Output is correct
78 Correct 531 ms 47040 KB Output is correct
79 Correct 532 ms 47128 KB Output is correct
80 Correct 541 ms 47192 KB Output is correct
81 Correct 537 ms 47216 KB Output is correct
82 Correct 563 ms 47116 KB Output is correct
83 Correct 525 ms 47196 KB Output is correct
84 Correct 531 ms 47124 KB Output is correct