#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define ceil(a, b) ((a + b - 1) / (b))
#define all(x) x.begin(), x.end()
#define INF 1000000000000000000
#define eps (1e-9)
using namespace std;
#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
#ifdef wiwihorz
#define print(a...) kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); }
#else
#define print(...) 0
#define vprint(...) 0
#endif
namespace solver {
const int P = 6;
const int MOD = 998244353;
int ans = 0;
vector<vector<int>> cnt[11];
vector<int> cur;
vector<pii> edge = {
{0, 1}, {0, 4}, {0, 3},
{1, 5}, {1, 3}, {2, 3},
{2, 6}, {3, 7}, {5, 7},
{5, 4}, {6, 7}, {4, 6}
};
void init_() {
rep(i, 0, 10)
cnt[i].assign(P, vector<int>(P, 0));
cur.assign(8, 0);
ans = 0;
}
int count() {
int ans = 0, c;
rep(i, 3, 10) {
c = 1;
for(auto j : edge) {
c = c * cnt[i][cur[j.first]][cur[j.second]] % MOD;
if(!c) break;
}
ans = (ans + c) % MOD;
}
return ans;
}
void solve(int x) {
if(x == 8) ans = (ans + count()) % MOD;
else {
rep(i, 0, P - 1) {
cur[x] = i;
solve(x + 1);
}
}
}
};
using namespace solver;
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int n; cin >> n;
init_();
rep(i, 1, n) {
string s, s1; cin >> s;
int sz = s.size();
cnt[sz][s[0] - 'a'][s.back() - 'a'] ++;
s1 = s, reverse(all(s1));
if(s != s1) cnt[sz][s1[0] - 'a'][s1.back() - 'a'] ++;
}
solve(0);
cout << ans << "\n";
return 0;
}
Compilation message
cubeword.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
4 | #pragma loop-opt(on)
|
cubeword.cpp:22:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
22 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
cubeword.cpp:22:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
22 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
842 ms |
1168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
842 ms |
1168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
842 ms |
1168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
842 ms |
1168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |