답안 #578890

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578890 2022-06-18T07:25:39 Z amunduzbaev Cubeword (CEOI19_cubeword) C++17
50 / 100
165 ms 34804 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
typedef int64_t ll;

const int N = 1e5 + 5;
const int M = 26;
const int mod = 119 << 23 | 1;
int is[M][M], pre[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';
			if('A' <= x && x <= 'Z') x = x - 'A' + 26;
			if('0' <= x && x <= '9') x = x - '0' + 52;
		}
		
		string b = a[i];
		reverse(b.begin(), b.end());
		a.push_back(b);
	}
	
	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=0;j<M;j++){
				for(int k=0;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;
					}
					//~ if(pre[i][j][k]){
						//~ cout<<i<<" "<<j<<" "<<k<<"\n";
						//~ cout<<pre[i][j][k]<<"\n";
					//~ }
				}
			}
		}
		
		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++){
						int res = 1;
						res = res * 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 = (tot + res) % 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:54:14: warning: array subscript has type 'char' [-Wchar-subscripts]
   54 |    is[a[l][0]][a[l][s-1]]++;
      |              ^
cubeword.cpp:54:25: warning: array subscript has type 'char' [-Wchar-subscripts]
   54 |    is[a[l][0]][a[l][s-1]]++;
      |                         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 18868 KB Output is correct
2 Correct 138 ms 18888 KB Output is correct
3 Correct 137 ms 18868 KB Output is correct
4 Correct 132 ms 18868 KB Output is correct
5 Correct 132 ms 18880 KB Output is correct
6 Correct 142 ms 18868 KB Output is correct
7 Correct 136 ms 18880 KB Output is correct
8 Correct 145 ms 18836 KB Output is correct
9 Correct 148 ms 18812 KB Output is correct
10 Correct 139 ms 18868 KB Output is correct
11 Correct 138 ms 18876 KB Output is correct
12 Correct 135 ms 18828 KB Output is correct
13 Correct 158 ms 18872 KB Output is correct
14 Correct 131 ms 18868 KB Output is correct
15 Correct 135 ms 18828 KB Output is correct
16 Correct 138 ms 18832 KB Output is correct
17 Correct 140 ms 18872 KB Output is correct
18 Correct 140 ms 18832 KB Output is correct
19 Correct 137 ms 18872 KB Output is correct
20 Correct 148 ms 18876 KB Output is correct
21 Correct 132 ms 18872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 18868 KB Output is correct
2 Correct 138 ms 18888 KB Output is correct
3 Correct 137 ms 18868 KB Output is correct
4 Correct 132 ms 18868 KB Output is correct
5 Correct 132 ms 18880 KB Output is correct
6 Correct 142 ms 18868 KB Output is correct
7 Correct 136 ms 18880 KB Output is correct
8 Correct 145 ms 18836 KB Output is correct
9 Correct 148 ms 18812 KB Output is correct
10 Correct 139 ms 18868 KB Output is correct
11 Correct 138 ms 18876 KB Output is correct
12 Correct 135 ms 18828 KB Output is correct
13 Correct 158 ms 18872 KB Output is correct
14 Correct 131 ms 18868 KB Output is correct
15 Correct 135 ms 18828 KB Output is correct
16 Correct 138 ms 18832 KB Output is correct
17 Correct 140 ms 18872 KB Output is correct
18 Correct 140 ms 18832 KB Output is correct
19 Correct 137 ms 18872 KB Output is correct
20 Correct 148 ms 18876 KB Output is correct
21 Correct 132 ms 18872 KB Output is correct
22 Correct 131 ms 18868 KB Output is correct
23 Correct 135 ms 19596 KB Output is correct
24 Correct 151 ms 19680 KB Output is correct
25 Correct 161 ms 19660 KB Output is correct
26 Correct 134 ms 19644 KB Output is correct
27 Correct 141 ms 19652 KB Output is correct
28 Correct 137 ms 19624 KB Output is correct
29 Correct 133 ms 19652 KB Output is correct
30 Correct 129 ms 19644 KB Output is correct
31 Correct 135 ms 19660 KB Output is correct
32 Correct 130 ms 19760 KB Output is correct
33 Correct 148 ms 19652 KB Output is correct
34 Correct 137 ms 19652 KB Output is correct
35 Correct 131 ms 19644 KB Output is correct
36 Correct 139 ms 19656 KB Output is correct
37 Correct 133 ms 19644 KB Output is correct
38 Correct 145 ms 19656 KB Output is correct
39 Correct 148 ms 19724 KB Output is correct
40 Correct 135 ms 19600 KB Output is correct
41 Correct 134 ms 19640 KB Output is correct
42 Correct 142 ms 19644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 18868 KB Output is correct
2 Correct 138 ms 18888 KB Output is correct
3 Correct 137 ms 18868 KB Output is correct
4 Correct 132 ms 18868 KB Output is correct
5 Correct 132 ms 18880 KB Output is correct
6 Correct 142 ms 18868 KB Output is correct
7 Correct 136 ms 18880 KB Output is correct
8 Correct 145 ms 18836 KB Output is correct
9 Correct 148 ms 18812 KB Output is correct
10 Correct 139 ms 18868 KB Output is correct
11 Correct 138 ms 18876 KB Output is correct
12 Correct 135 ms 18828 KB Output is correct
13 Correct 158 ms 18872 KB Output is correct
14 Correct 131 ms 18868 KB Output is correct
15 Correct 135 ms 18828 KB Output is correct
16 Correct 138 ms 18832 KB Output is correct
17 Correct 140 ms 18872 KB Output is correct
18 Correct 140 ms 18832 KB Output is correct
19 Correct 137 ms 18872 KB Output is correct
20 Correct 148 ms 18876 KB Output is correct
21 Correct 132 ms 18872 KB Output is correct
22 Correct 131 ms 18868 KB Output is correct
23 Correct 135 ms 19596 KB Output is correct
24 Correct 151 ms 19680 KB Output is correct
25 Correct 161 ms 19660 KB Output is correct
26 Correct 134 ms 19644 KB Output is correct
27 Correct 141 ms 19652 KB Output is correct
28 Correct 137 ms 19624 KB Output is correct
29 Correct 133 ms 19652 KB Output is correct
30 Correct 129 ms 19644 KB Output is correct
31 Correct 135 ms 19660 KB Output is correct
32 Correct 130 ms 19760 KB Output is correct
33 Correct 148 ms 19652 KB Output is correct
34 Correct 137 ms 19652 KB Output is correct
35 Correct 131 ms 19644 KB Output is correct
36 Correct 139 ms 19656 KB Output is correct
37 Correct 133 ms 19644 KB Output is correct
38 Correct 145 ms 19656 KB Output is correct
39 Correct 148 ms 19724 KB Output is correct
40 Correct 135 ms 19600 KB Output is correct
41 Correct 134 ms 19640 KB Output is correct
42 Correct 142 ms 19644 KB Output is correct
43 Runtime error 165 ms 34804 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 18868 KB Output is correct
2 Correct 138 ms 18888 KB Output is correct
3 Correct 137 ms 18868 KB Output is correct
4 Correct 132 ms 18868 KB Output is correct
5 Correct 132 ms 18880 KB Output is correct
6 Correct 142 ms 18868 KB Output is correct
7 Correct 136 ms 18880 KB Output is correct
8 Correct 145 ms 18836 KB Output is correct
9 Correct 148 ms 18812 KB Output is correct
10 Correct 139 ms 18868 KB Output is correct
11 Correct 138 ms 18876 KB Output is correct
12 Correct 135 ms 18828 KB Output is correct
13 Correct 158 ms 18872 KB Output is correct
14 Correct 131 ms 18868 KB Output is correct
15 Correct 135 ms 18828 KB Output is correct
16 Correct 138 ms 18832 KB Output is correct
17 Correct 140 ms 18872 KB Output is correct
18 Correct 140 ms 18832 KB Output is correct
19 Correct 137 ms 18872 KB Output is correct
20 Correct 148 ms 18876 KB Output is correct
21 Correct 132 ms 18872 KB Output is correct
22 Correct 131 ms 18868 KB Output is correct
23 Correct 135 ms 19596 KB Output is correct
24 Correct 151 ms 19680 KB Output is correct
25 Correct 161 ms 19660 KB Output is correct
26 Correct 134 ms 19644 KB Output is correct
27 Correct 141 ms 19652 KB Output is correct
28 Correct 137 ms 19624 KB Output is correct
29 Correct 133 ms 19652 KB Output is correct
30 Correct 129 ms 19644 KB Output is correct
31 Correct 135 ms 19660 KB Output is correct
32 Correct 130 ms 19760 KB Output is correct
33 Correct 148 ms 19652 KB Output is correct
34 Correct 137 ms 19652 KB Output is correct
35 Correct 131 ms 19644 KB Output is correct
36 Correct 139 ms 19656 KB Output is correct
37 Correct 133 ms 19644 KB Output is correct
38 Correct 145 ms 19656 KB Output is correct
39 Correct 148 ms 19724 KB Output is correct
40 Correct 135 ms 19600 KB Output is correct
41 Correct 134 ms 19640 KB Output is correct
42 Correct 142 ms 19644 KB Output is correct
43 Runtime error 165 ms 34804 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -