#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXK=10;
const int MAXN=1e5+6;
map<char,int>mp;
const ll mod=998244353;
string s[MAXN];
int cnt[100][100];
int ans=0,n;
int dp[100][100][100];
void solve(int d)
{
memset(cnt,0,sizeof(cnt));
memset(dp,0,sizeof(dp));
set<string>used;
for(int i=0;i<n;i++)
{
if(s[i].size()!=d)continue;
if(used.find(s[i])==used.end())
{
used.insert(s[i]);
cnt[mp[s[i][0]]][mp[s[i][s[i].size()-1]]]++;
}
reverse(s[i].begin(),s[i].end());
if(used.find(s[i])==used.end())
{
used.insert(s[i]);
cnt[mp[s[i][0]]][mp[s[i][s[i].size()-1]]]++;
}
reverse(s[i].begin(),s[i].end());
}
if(used.size()==0)return;
//cout<<d<<endl;
for(int i1=1;i1<=MAXK;i1++)
{
for(int i2=1;i2<=MAXK;i2++)
{
for(int i3=1;i3<=MAXK;i3++)
{
for(int j=1;j<=MAXK;j++)
{
dp[i1][i2][i3]=dp[i1][i2][i3]+((ll)((ll)cnt[j][i1]*cnt[j][i2])%mod*cnt[j][i3])%mod;
dp[i1][i2][i3]%=mod;
}
}
}
}
for(int i1=1;i1<=MAXK;i1++)
{
for(int i2=1;i2<=MAXK;i2++)
{
for(int i3=1;i3<=MAXK;i3++)
{
for(int i4=1;i4<=MAXK;i4++)
{
ans=ans+((ll)(((ll)(((ll)dp[i1][i2][i3]*dp[i1][i2][i4])%mod)*dp[i1][i3][i4])%mod)*dp[i2][i3][i4])%mod;
ans%=mod;
}
}
}
}
}
int main()
{
for(char c='a';c<='z';c++)mp[c]=c-'a'+1;
for(char c='A';c<='Z';c++)mp[c]=c-'A'+27;
for(char c='0';c<='9';c++)mp[c]=c-'a'+43;
cin>>n;
for(int i=0;i<n;i++)cin>>s[i];
for(int i=3;i<=10;i++)
{
solve(i);
}
cout<<ans<<endl;
return 0;
}
Compilation message
cubeword.cpp: In function 'void solve(int)':
cubeword.cpp:19:17: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
19 | if(s[i].size()!=d)continue;
| ~~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
181 ms |
10476 KB |
Output is correct |
2 |
Correct |
190 ms |
11244 KB |
Output is correct |
3 |
Correct |
182 ms |
11372 KB |
Output is correct |
4 |
Correct |
183 ms |
11372 KB |
Output is correct |
5 |
Correct |
178 ms |
11336 KB |
Output is correct |
6 |
Correct |
180 ms |
11372 KB |
Output is correct |
7 |
Correct |
188 ms |
11372 KB |
Output is correct |
8 |
Correct |
189 ms |
11460 KB |
Output is correct |
9 |
Correct |
186 ms |
11500 KB |
Output is correct |
10 |
Correct |
177 ms |
11244 KB |
Output is correct |
11 |
Correct |
178 ms |
11244 KB |
Output is correct |
12 |
Correct |
178 ms |
11264 KB |
Output is correct |
13 |
Correct |
178 ms |
11244 KB |
Output is correct |
14 |
Correct |
184 ms |
11372 KB |
Output is correct |
15 |
Correct |
178 ms |
11244 KB |
Output is correct |
16 |
Correct |
179 ms |
11392 KB |
Output is correct |
17 |
Correct |
182 ms |
11372 KB |
Output is correct |
18 |
Correct |
176 ms |
11244 KB |
Output is correct |
19 |
Correct |
181 ms |
11244 KB |
Output is correct |
20 |
Correct |
185 ms |
11244 KB |
Output is correct |
21 |
Correct |
175 ms |
11244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
181 ms |
10476 KB |
Output is correct |
2 |
Correct |
190 ms |
11244 KB |
Output is correct |
3 |
Correct |
182 ms |
11372 KB |
Output is correct |
4 |
Correct |
183 ms |
11372 KB |
Output is correct |
5 |
Correct |
178 ms |
11336 KB |
Output is correct |
6 |
Correct |
180 ms |
11372 KB |
Output is correct |
7 |
Correct |
188 ms |
11372 KB |
Output is correct |
8 |
Correct |
189 ms |
11460 KB |
Output is correct |
9 |
Correct |
186 ms |
11500 KB |
Output is correct |
10 |
Correct |
177 ms |
11244 KB |
Output is correct |
11 |
Correct |
178 ms |
11244 KB |
Output is correct |
12 |
Correct |
178 ms |
11264 KB |
Output is correct |
13 |
Correct |
178 ms |
11244 KB |
Output is correct |
14 |
Correct |
184 ms |
11372 KB |
Output is correct |
15 |
Correct |
178 ms |
11244 KB |
Output is correct |
16 |
Correct |
179 ms |
11392 KB |
Output is correct |
17 |
Correct |
182 ms |
11372 KB |
Output is correct |
18 |
Correct |
176 ms |
11244 KB |
Output is correct |
19 |
Correct |
181 ms |
11244 KB |
Output is correct |
20 |
Correct |
185 ms |
11244 KB |
Output is correct |
21 |
Correct |
175 ms |
11244 KB |
Output is correct |
22 |
Incorrect |
169 ms |
10476 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
181 ms |
10476 KB |
Output is correct |
2 |
Correct |
190 ms |
11244 KB |
Output is correct |
3 |
Correct |
182 ms |
11372 KB |
Output is correct |
4 |
Correct |
183 ms |
11372 KB |
Output is correct |
5 |
Correct |
178 ms |
11336 KB |
Output is correct |
6 |
Correct |
180 ms |
11372 KB |
Output is correct |
7 |
Correct |
188 ms |
11372 KB |
Output is correct |
8 |
Correct |
189 ms |
11460 KB |
Output is correct |
9 |
Correct |
186 ms |
11500 KB |
Output is correct |
10 |
Correct |
177 ms |
11244 KB |
Output is correct |
11 |
Correct |
178 ms |
11244 KB |
Output is correct |
12 |
Correct |
178 ms |
11264 KB |
Output is correct |
13 |
Correct |
178 ms |
11244 KB |
Output is correct |
14 |
Correct |
184 ms |
11372 KB |
Output is correct |
15 |
Correct |
178 ms |
11244 KB |
Output is correct |
16 |
Correct |
179 ms |
11392 KB |
Output is correct |
17 |
Correct |
182 ms |
11372 KB |
Output is correct |
18 |
Correct |
176 ms |
11244 KB |
Output is correct |
19 |
Correct |
181 ms |
11244 KB |
Output is correct |
20 |
Correct |
185 ms |
11244 KB |
Output is correct |
21 |
Correct |
175 ms |
11244 KB |
Output is correct |
22 |
Incorrect |
169 ms |
10476 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
181 ms |
10476 KB |
Output is correct |
2 |
Correct |
190 ms |
11244 KB |
Output is correct |
3 |
Correct |
182 ms |
11372 KB |
Output is correct |
4 |
Correct |
183 ms |
11372 KB |
Output is correct |
5 |
Correct |
178 ms |
11336 KB |
Output is correct |
6 |
Correct |
180 ms |
11372 KB |
Output is correct |
7 |
Correct |
188 ms |
11372 KB |
Output is correct |
8 |
Correct |
189 ms |
11460 KB |
Output is correct |
9 |
Correct |
186 ms |
11500 KB |
Output is correct |
10 |
Correct |
177 ms |
11244 KB |
Output is correct |
11 |
Correct |
178 ms |
11244 KB |
Output is correct |
12 |
Correct |
178 ms |
11264 KB |
Output is correct |
13 |
Correct |
178 ms |
11244 KB |
Output is correct |
14 |
Correct |
184 ms |
11372 KB |
Output is correct |
15 |
Correct |
178 ms |
11244 KB |
Output is correct |
16 |
Correct |
179 ms |
11392 KB |
Output is correct |
17 |
Correct |
182 ms |
11372 KB |
Output is correct |
18 |
Correct |
176 ms |
11244 KB |
Output is correct |
19 |
Correct |
181 ms |
11244 KB |
Output is correct |
20 |
Correct |
185 ms |
11244 KB |
Output is correct |
21 |
Correct |
175 ms |
11244 KB |
Output is correct |
22 |
Incorrect |
169 ms |
10476 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |