Submission #203788

# Submission time Handle Problem Language Result Execution time Memory
203788 2020-02-22T06:56:23 Z dndhk Cubeword (CEOI19_cubeword) C++14
84 / 100
1100 ms 8560 KB
#include <bits/stdc++.h>

#define pb push_back

using namespace std;

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

const ll MOD = 998244353;
const int MAX_N = 100000;
const int MAX_K = 62;

int N;
vector<string> str[11];
set<string> st;
ll cnt[MAX_K+1][MAX_K+1];
ll cnt2[MAX_K+1][MAX_K+1][MAX_K+1];
string s;

ll ans = 0;

int calc(char c){
	if(c>='0' && c<='9'){
		return c-'0';
	}
	if(c>='A' && c<='Z'){
		return c-'A'+10;
	}
	if(c>='a' && c<='z'){
		return c-'a'+36;
	}
}

void solve(){
	for(int i=0; i<MAX_K; i++)	for(int j=0; j<MAX_K; j++)	for(int k=0; k<MAX_K; k++)	cnt2[i][j][k] = 0;
	for(int i=0; i<MAX_K; i++){ 
		for(int j=0; j<MAX_K; j++){
			for(int k=0; k<MAX_K; k++){
				if(cnt[i][k]==0 || cnt[j][k]==0)	continue;
				for(int t=0; t<MAX_K; t++){
					cnt2[i][j][t] = (cnt2[i][j][t] + (cnt[i][k] * cnt[j][k] * cnt[k][t] % MOD)) %  MOD;
				}
			}
		}
	}
	for(int i=0; i<MAX_K; i++){
		for(int j=0; j<MAX_K; j++){
			for(int k=0; k<MAX_K; k++){
				if(cnt2[i][j][k]==0)	continue;
				for(int t=0; t<MAX_K; t++){
					ll d = cnt2[i][j][k]; d = (d * cnt2[i][j][t]) % MOD; d = (d * cnt2[i][k][t]) % MOD; d = (d * cnt2[j][k][t]) % MOD;
					//if(d!=0)	cout<<i<<" "<<j<<" "<<k<<" "<<t<<" "<<d<<endl;
					ans = (ans + d) % MOD;
				}
			}
		}
	}
}

int main(){
	scanf("%d", &N);
	for(int i=1; i<=N; i++){
		cin>>s;
		str[s.size()].pb(s);
	}
	for(int l=3; l<=10; l++){
		if(str[l].empty())	continue;
		st.clear();
		for(int j=0; j<MAX_K; j++){
			for(int k=0; k<MAX_K; k++){
				cnt[j][k] = 0;
			}
		}
		while(!str[l].empty()){
			s = str[l].back(); str[l].pop_back();
			if(st.find(s)==st.end()){
				st.insert(s);
				cnt[calc(s[0])][calc(s.back())]++; 
			}
			for(int i=0; i<l/2; i++){
				char c = s[i]; s[i] = s[l-1-i]; s[l-1-i] = c;
			}
			if(st.find(s)==st.end()){
				st.insert(s);
				cnt[calc(s[0])][calc(s.back())]++; 
			}
		}
 		solve();
	}
	printf("%lld", ans);
	return 0;
}

Compilation message

cubeword.cpp: In function 'int calc(char)':
cubeword.cpp:33:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
cubeword.cpp: In function 'int main()':
cubeword.cpp:62:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 211 ms 8520 KB Output is correct
2 Correct 216 ms 8424 KB Output is correct
3 Correct 206 ms 8524 KB Output is correct
4 Correct 211 ms 8468 KB Output is correct
5 Correct 208 ms 8516 KB Output is correct
6 Correct 208 ms 8560 KB Output is correct
7 Correct 209 ms 8512 KB Output is correct
8 Correct 213 ms 8456 KB Output is correct
9 Correct 206 ms 8488 KB Output is correct
10 Correct 210 ms 8432 KB Output is correct
11 Correct 208 ms 8424 KB Output is correct
12 Correct 216 ms 8524 KB Output is correct
13 Correct 206 ms 8392 KB Output is correct
14 Correct 208 ms 8528 KB Output is correct
15 Correct 205 ms 8408 KB Output is correct
16 Correct 210 ms 8428 KB Output is correct
17 Correct 211 ms 8540 KB Output is correct
18 Correct 210 ms 8412 KB Output is correct
19 Correct 207 ms 8448 KB Output is correct
20 Correct 215 ms 8472 KB Output is correct
21 Correct 213 ms 8524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 8520 KB Output is correct
2 Correct 216 ms 8424 KB Output is correct
3 Correct 206 ms 8524 KB Output is correct
4 Correct 211 ms 8468 KB Output is correct
5 Correct 208 ms 8516 KB Output is correct
6 Correct 208 ms 8560 KB Output is correct
7 Correct 209 ms 8512 KB Output is correct
8 Correct 213 ms 8456 KB Output is correct
9 Correct 206 ms 8488 KB Output is correct
10 Correct 210 ms 8432 KB Output is correct
11 Correct 208 ms 8424 KB Output is correct
12 Correct 216 ms 8524 KB Output is correct
13 Correct 206 ms 8392 KB Output is correct
14 Correct 208 ms 8528 KB Output is correct
15 Correct 205 ms 8408 KB Output is correct
16 Correct 210 ms 8428 KB Output is correct
17 Correct 211 ms 8540 KB Output is correct
18 Correct 210 ms 8412 KB Output is correct
19 Correct 207 ms 8448 KB Output is correct
20 Correct 215 ms 8472 KB Output is correct
21 Correct 213 ms 8524 KB Output is correct
22 Correct 218 ms 7680 KB Output is correct
23 Correct 223 ms 7764 KB Output is correct
24 Correct 228 ms 7668 KB Output is correct
25 Correct 217 ms 7652 KB Output is correct
26 Correct 217 ms 7672 KB Output is correct
27 Correct 218 ms 7760 KB Output is correct
28 Correct 225 ms 7564 KB Output is correct
29 Correct 228 ms 7872 KB Output is correct
30 Correct 220 ms 7712 KB Output is correct
31 Correct 220 ms 7628 KB Output is correct
32 Correct 218 ms 7784 KB Output is correct
33 Correct 237 ms 7804 KB Output is correct
34 Correct 215 ms 7640 KB Output is correct
35 Correct 214 ms 7724 KB Output is correct
36 Correct 219 ms 7764 KB Output is correct
37 Correct 215 ms 7660 KB Output is correct
38 Correct 220 ms 7688 KB Output is correct
39 Correct 223 ms 7700 KB Output is correct
40 Correct 221 ms 7692 KB Output is correct
41 Correct 227 ms 7572 KB Output is correct
42 Correct 211 ms 7584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 8520 KB Output is correct
2 Correct 216 ms 8424 KB Output is correct
3 Correct 206 ms 8524 KB Output is correct
4 Correct 211 ms 8468 KB Output is correct
5 Correct 208 ms 8516 KB Output is correct
6 Correct 208 ms 8560 KB Output is correct
7 Correct 209 ms 8512 KB Output is correct
8 Correct 213 ms 8456 KB Output is correct
9 Correct 206 ms 8488 KB Output is correct
10 Correct 210 ms 8432 KB Output is correct
11 Correct 208 ms 8424 KB Output is correct
12 Correct 216 ms 8524 KB Output is correct
13 Correct 206 ms 8392 KB Output is correct
14 Correct 208 ms 8528 KB Output is correct
15 Correct 205 ms 8408 KB Output is correct
16 Correct 210 ms 8428 KB Output is correct
17 Correct 211 ms 8540 KB Output is correct
18 Correct 210 ms 8412 KB Output is correct
19 Correct 207 ms 8448 KB Output is correct
20 Correct 215 ms 8472 KB Output is correct
21 Correct 213 ms 8524 KB Output is correct
22 Correct 218 ms 7680 KB Output is correct
23 Correct 223 ms 7764 KB Output is correct
24 Correct 228 ms 7668 KB Output is correct
25 Correct 217 ms 7652 KB Output is correct
26 Correct 217 ms 7672 KB Output is correct
27 Correct 218 ms 7760 KB Output is correct
28 Correct 225 ms 7564 KB Output is correct
29 Correct 228 ms 7872 KB Output is correct
30 Correct 220 ms 7712 KB Output is correct
31 Correct 220 ms 7628 KB Output is correct
32 Correct 218 ms 7784 KB Output is correct
33 Correct 237 ms 7804 KB Output is correct
34 Correct 215 ms 7640 KB Output is correct
35 Correct 214 ms 7724 KB Output is correct
36 Correct 219 ms 7764 KB Output is correct
37 Correct 215 ms 7660 KB Output is correct
38 Correct 220 ms 7688 KB Output is correct
39 Correct 223 ms 7700 KB Output is correct
40 Correct 221 ms 7692 KB Output is correct
41 Correct 227 ms 7572 KB Output is correct
42 Correct 211 ms 7584 KB Output is correct
43 Correct 391 ms 7516 KB Output is correct
44 Correct 396 ms 7768 KB Output is correct
45 Correct 385 ms 7680 KB Output is correct
46 Correct 390 ms 7404 KB Output is correct
47 Correct 389 ms 7588 KB Output is correct
48 Correct 377 ms 7616 KB Output is correct
49 Correct 390 ms 7412 KB Output is correct
50 Correct 387 ms 7616 KB Output is correct
51 Correct 398 ms 7572 KB Output is correct
52 Correct 388 ms 7568 KB Output is correct
53 Correct 385 ms 7528 KB Output is correct
54 Correct 387 ms 7488 KB Output is correct
55 Correct 391 ms 7760 KB Output is correct
56 Correct 395 ms 7528 KB Output is correct
57 Correct 385 ms 7532 KB Output is correct
58 Correct 385 ms 7740 KB Output is correct
59 Correct 389 ms 7620 KB Output is correct
60 Correct 381 ms 7568 KB Output is correct
61 Correct 382 ms 7608 KB Output is correct
62 Correct 391 ms 7428 KB Output is correct
63 Correct 400 ms 7432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 8520 KB Output is correct
2 Correct 216 ms 8424 KB Output is correct
3 Correct 206 ms 8524 KB Output is correct
4 Correct 211 ms 8468 KB Output is correct
5 Correct 208 ms 8516 KB Output is correct
6 Correct 208 ms 8560 KB Output is correct
7 Correct 209 ms 8512 KB Output is correct
8 Correct 213 ms 8456 KB Output is correct
9 Correct 206 ms 8488 KB Output is correct
10 Correct 210 ms 8432 KB Output is correct
11 Correct 208 ms 8424 KB Output is correct
12 Correct 216 ms 8524 KB Output is correct
13 Correct 206 ms 8392 KB Output is correct
14 Correct 208 ms 8528 KB Output is correct
15 Correct 205 ms 8408 KB Output is correct
16 Correct 210 ms 8428 KB Output is correct
17 Correct 211 ms 8540 KB Output is correct
18 Correct 210 ms 8412 KB Output is correct
19 Correct 207 ms 8448 KB Output is correct
20 Correct 215 ms 8472 KB Output is correct
21 Correct 213 ms 8524 KB Output is correct
22 Correct 218 ms 7680 KB Output is correct
23 Correct 223 ms 7764 KB Output is correct
24 Correct 228 ms 7668 KB Output is correct
25 Correct 217 ms 7652 KB Output is correct
26 Correct 217 ms 7672 KB Output is correct
27 Correct 218 ms 7760 KB Output is correct
28 Correct 225 ms 7564 KB Output is correct
29 Correct 228 ms 7872 KB Output is correct
30 Correct 220 ms 7712 KB Output is correct
31 Correct 220 ms 7628 KB Output is correct
32 Correct 218 ms 7784 KB Output is correct
33 Correct 237 ms 7804 KB Output is correct
34 Correct 215 ms 7640 KB Output is correct
35 Correct 214 ms 7724 KB Output is correct
36 Correct 219 ms 7764 KB Output is correct
37 Correct 215 ms 7660 KB Output is correct
38 Correct 220 ms 7688 KB Output is correct
39 Correct 223 ms 7700 KB Output is correct
40 Correct 221 ms 7692 KB Output is correct
41 Correct 227 ms 7572 KB Output is correct
42 Correct 211 ms 7584 KB Output is correct
43 Correct 391 ms 7516 KB Output is correct
44 Correct 396 ms 7768 KB Output is correct
45 Correct 385 ms 7680 KB Output is correct
46 Correct 390 ms 7404 KB Output is correct
47 Correct 389 ms 7588 KB Output is correct
48 Correct 377 ms 7616 KB Output is correct
49 Correct 390 ms 7412 KB Output is correct
50 Correct 387 ms 7616 KB Output is correct
51 Correct 398 ms 7572 KB Output is correct
52 Correct 388 ms 7568 KB Output is correct
53 Correct 385 ms 7528 KB Output is correct
54 Correct 387 ms 7488 KB Output is correct
55 Correct 391 ms 7760 KB Output is correct
56 Correct 395 ms 7528 KB Output is correct
57 Correct 385 ms 7532 KB Output is correct
58 Correct 385 ms 7740 KB Output is correct
59 Correct 389 ms 7620 KB Output is correct
60 Correct 381 ms 7568 KB Output is correct
61 Correct 382 ms 7608 KB Output is correct
62 Correct 391 ms 7428 KB Output is correct
63 Correct 400 ms 7432 KB Output is correct
64 Execution timed out 1190 ms 7452 KB Time limit exceeded
65 Halted 0 ms 0 KB -