//Sylwia Sapkowska
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << "'" << x << "'";}
void __print(const char *x) {cerr << '"' << x << '"';}
void __print(const string &x) {cerr << '"' << x << '"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define int long long
typedef pair<int, int> T;
const int oo = 1e18, oo2 = 1e9+7, K = 30;
const int mod = 998244353;
const int A = 11, mx = 76;
int mul(int a, int b){
return (a*b)%mod;
}
void add(int &a, int b){
a += b;
if (a >= mod) a-= mod;
}
void solve(){
int n; cin >> n;
vector cnt(A, vector<vector<int>>(mx, vector<int>(mx)));
set<string>a;
for (int i = 0; i<n; i++){
string s; cin >> s;
int l = (int)s.size();
if (a.find(s) == a.end()){
a.insert(s);
cnt[l][s[0]-'0'][s.back()-'0']++;
}
auto t = s;
reverse(t.begin(), t.end());
if (a.find(t) == a.end()) {
cnt[l][s.back()-'0'][s[0]-'0']++;
a.insert(t);
}
}
int ans = 0;
vector zlicz(mx, vector<vector<int>>(mx, vector<int>(mx)));
for (int rep = 3; rep < A; rep++){
debug(rep);
for (int a = 0; a < mx; a++){
for (int b = 0; b < mx; b++){
for (int c = 0; c < mx; c++){
zlicz[a][b][c] = 0;
}
}
}
for (int beg = 0; beg < mx; beg++){
for (int a = 0; a < mx; a++){
for (int b = 0; b < mx; b++){
for (int c = 0; c < mx; c++){
add(zlicz[a][b][c], mul(cnt[rep][beg][a], mul(cnt[rep][beg][b], cnt[rep][beg][c])));
}
}
}
}
for (int a = 0; a < mx; a++){
for (int b = 0; b < mx; b++){
for (int c = 0; c < mx; c++){
for (int d = 0; d < mx; d++){
add(ans, mul(mul(zlicz[a][b][c], zlicz[a][c][d]), mul(zlicz[b][c][d], zlicz[a][b][d])));
}
}
}
}
}
cout << ans << "\n";
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1156 ms |
19928 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1156 ms |
19928 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1156 ms |
19928 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1156 ms |
19928 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |