답안 #945684

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
945684 2024-03-14T06:25:06 Z Minbaev Cubeword (CEOI19_cubeword) C++17
0 / 100
162 ms 15140 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[33][33][33];
int v[33][33];
int ans = 0;
int n,m,k;

map<char,int>mps;

vector<int>vs;

int ii(char ch){
	return mps[ch];	
}

int cnt = 0;

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

*/
signed main()
{
	for(int i = 0;i<='p'-'a';i+=1){
		mps['a'+i] = cnt++;
	}
	for(int i = 0;i<='p'-'a';i+=1){
		mps['A'+i] = cnt++;
	}
	
	
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int tt=1;//cin>>tt>>n;
	while(tt--)solve();

}

# 결과 실행 시간 메모리 Grader output
1 Incorrect 162 ms 15140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 162 ms 15140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 162 ms 15140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 162 ms 15140 KB Output isn't correct
2 Halted 0 ms 0 KB -