#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("popcnt")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=2e5+10,P=998244353;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
const ldb eps=1e-6;
const ldb PI=acos(-1.0);
const int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
// const string ct="abcdefghijklmnopqrstuvwxyz";
const string ct="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
// const string ct="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
const int cs = ct.size();
template<typename T>
using vvector = vector<vector<T>>;
ll cnt[128][128];
ll cnt3[70][70][70];
ll solve(vector<string> &ss) {
sort(all(ss));
ss.resize(unique(all(ss))-ss.begin());
memset(cnt,0,sizeof(cnt));
for (auto s:ss) {
cnt[s[0]][s.back()]++;
}
memset(cnt3,0,sizeof(cnt3));
for (int i=0;i<cs;i++) {
for (int j=i;j<cs;j++) {
for (int k=j;k<cs;k++) {
ll ans=0;
for (int l=0;l<cs;l++) {
ans+=cnt[ct[i]][ct[l]]*cnt[ct[j]][ct[l]]%P*cnt[ct[k]][ct[l]]%P;
ans%=P;
}
cnt3[i][j][k]=ans;
}
}
}
auto srt = [&](int a,int b,int c,int d) {
array<int,4> ans={a,b,c,d};
sort(all(ans));
return ans;
};
ll ans=0;
for (int i=0;i<cs;i++) {
for (int j=0;j<cs;j++) {
for (int k=0;k<cs;k++) {
for (int l=0;l<cs;l++) {
ll now=1;
auto [ni,nj,nk,nl] = srt(i,j,k,l);
now*=cnt3[ni][nj][nk];
now%=P;
now*=cnt3[ni][nj][nl];
now%=P;
now*=cnt3[ni][nk][nl];
now%=P;
now*=cnt3[nj][nk][nl];
now%=P;
ans+=now;
ans%=P;
}
}
}
}
return ans;
}
int main() {
speed;
int n;
vector<string> l[11];
cin>>n;
for (int i=0;i<n;i++) {
string s;
cin>>s;
l[s.size()].push_back(s);
reverse(all(s));
l[s.size()].push_back(s);
}
ll ans=0;
for (int k=3;k<=10;k++) {
// cout<<k<<" k\n"<<flush;
ans+=solve(l[k]);
ans%=P;
}
cout<<ans<<"\n";
return 0;
}
Compilation message
cubeword.cpp: In function 'll solve(std::vector<std::__cxx11::basic_string<char> >&)':
cubeword.cpp:37:17: warning: array subscript has type 'char' [-Wchar-subscripts]
37 | cnt[s[0]][s.back()]++;
| ^
cubeword.cpp:37:25: warning: array subscript has type 'char' [-Wchar-subscripts]
37 | cnt[s[0]][s.back()]++;
| ~~~~~~^~
cubeword.cpp:45:35: warning: array subscript has type 'char' [-Wchar-subscripts]
45 | ans+=cnt[ct[i]][ct[l]]*cnt[ct[j]][ct[l]]%P*cnt[ct[k]][ct[l]]%P;
| ^
cubeword.cpp:45:42: warning: array subscript has type 'char' [-Wchar-subscripts]
45 | ans+=cnt[ct[i]][ct[l]]*cnt[ct[j]][ct[l]]%P*cnt[ct[k]][ct[l]]%P;
| ^
cubeword.cpp:45:53: warning: array subscript has type 'char' [-Wchar-subscripts]
45 | ans+=cnt[ct[i]][ct[l]]*cnt[ct[j]][ct[l]]%P*cnt[ct[k]][ct[l]]%P;
| ^
cubeword.cpp:45:60: warning: array subscript has type 'char' [-Wchar-subscripts]
45 | ans+=cnt[ct[i]][ct[l]]*cnt[ct[j]][ct[l]]%P*cnt[ct[k]][ct[l]]%P;
| ^
cubeword.cpp:45:73: warning: array subscript has type 'char' [-Wchar-subscripts]
45 | ans+=cnt[ct[i]][ct[l]]*cnt[ct[j]][ct[l]]%P*cnt[ct[k]][ct[l]]%P;
| ^
cubeword.cpp:45:80: warning: array subscript has type 'char' [-Wchar-subscripts]
45 | ans+=cnt[ct[i]][ct[l]]*cnt[ct[j]][ct[l]]%P*cnt[ct[k]][ct[l]]%P;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1164 ms |
14064 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1164 ms |
14064 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1164 ms |
14064 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1164 ms |
14064 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |