#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pii pair<int,int>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define f first
#define int long long
#define s second
#define pii pair<int,int>
template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;}
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
const int N=1e6 + 5 ;
const int inf = 1e18 + 7;
const int mod = 998244353;
int g[11][7][7];
vector<int>op[8];
int ans = 0;
void dfs(int sz, int ind, vector<int>v){
if(8 < ind){
int val = 1;
for(int i = 1;i<=7;i++){
for(auto to:op[i]){
val *= g[sz][v[i]][v[to]];
val %= mod;
}
}
ans += val;
ans %= mod;
return;
}
for(int i = 0;i<6;i++){
v[ind] = i;
dfs(sz,ind+1,v);
}
}
void solve(){
op[1] = {2,3,4};
op[2] = {5,8};
op[3] = {6,8};
op[4] = {5,6};
op[5] = {7};
op[6] = {7};
op[7] = {8};
int n,m,k;
map<string,int>mp;
cin >> n;
for(int i = 1;i<=n;i++){
string a;
cin >> a;
if(mp[a] == 0){
g[(int)a.size()][a[0] - 'a'][a[a.size()-1] - 'a'] += 1;
mp[a] += 1;
}
reverse(all(a));
if(mp[a] == 0){
g[(int)a.size()][a[0] - 'a'][a[a.size()-1] - 'a'] += 1;
mp[a] += 1;
}
}
for(int i = 3;i<=6;i++){
vector<int>v(9,-1);
dfs(i,1,v);
}
cout<<ans<<"\n";
}
/*
*/
signed main()
{
// freopen("seq.in", "r", stdin);
// freopen("seq.out", "w", stdout);
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int tt=1;//cin>>tt>>n;
while(tt--)solve();
}
Compilation message
cubeword.cpp: In function 'void solve()':
cubeword.cpp:61:8: warning: unused variable 'm' [-Wunused-variable]
61 | int n,m,k;
| ^
cubeword.cpp:61:10: warning: unused variable 'k' [-Wunused-variable]
61 | int n,m,k;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
586 ms |
15036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
586 ms |
15036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
586 ms |
15036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
586 ms |
15036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |