Submission #946813

#TimeUsernameProblemLanguageResultExecution timeMemory
946813galen_colinCubeword (CEOI19_cubeword)C++17
100 / 100
104 ms45696 KiB
/* not my code (obviously i don't code like this wtf) */ #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2") #include <bits/stdc++.h> using namespace std; #define int long long map<char, int> mp; int c[11][62][62][62]; int prod[11][62][62][62]; int aa[11][63][63]; const int mod = 998244353; const int msq = mod * mod; inline int mul(int x, int y){ if((x*y)>mod) return x*y%mod; return x*y; } using ll = long long; namespace modop { ll madd(ll a, ll b) { return (a + b) % mod; } ll msub(ll a, ll b) { return (((a - b) % mod) + mod) % mod; } ll mmul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; } ll mpow(ll base, ll exp) { ll res = 1; while (exp) { if (exp % 2 == 1){ res = (res * base) % mod; } exp >>= 1; base = (base * base) % mod; } return res; } ll minv(ll base) { return mpow(base, mod - 2); } ll mdiv(ll a, ll b) { return mmul(a, minv(b)); } const ll FACTORIAL_SIZE = 1.1e6; ll fact[FACTORIAL_SIZE], ifact[FACTORIAL_SIZE]; bool __factorials_generated__ = 0; void gen_factorial(ll n) { __factorials_generated__ = 1; fact[0] = fact[1] = ifact[0] = ifact[1] = 1; for (ll i = 2; i <= n; i++) { fact[i] = (i * fact[i - 1]) % mod; } ifact[n] = minv(fact[n]); for (ll i = n - 1; i >= 2; i--) { ifact[i] = ((i + 1) * ifact[i + 1]) % mod; } } ll nck(ll n, ll k) { if (!__factorials_generated__) { cerr << "Call gen_factorial you dope" << endl; exit(1); } if (k < 0 || n < k) return 0; ll den = (ifact[k] * ifact[n - k]) % mod; return (den * fact[n]) % mod; } } using namespace modop; void solve(){ ios_base::sync_with_stdio(false); cin.tie(0); int cnt=0; for(int i='a'; i<='z'; i++) mp[i]=cnt++; for(int i='A'; i<='Z'; i++) mp[i]=cnt++; for(int i='0'; i<='9'; i++) mp[i]=cnt++; int n; cin>>n; vector<string> s(n), x; for(auto &i: s){ cin >> i; string x = i; reverse(x.begin(), x.end()); if(x<i) i=x; } sort(s.begin(), s.end()); for(int i=0; i<n; i++){ if(i==0||s[i]!=s[i-1]) x.push_back(s[i]); } memset(aa, 0, sizeof aa); memset(c, 0, sizeof c); s=x; n = s.size(); for(int i=0; i<n; i++){ string x=s[i]; reverse(x.begin(), x.end()); if(x==s[i]) aa[x.size()][mp[x[0]]][mp[x.back()]]++; else aa[x.size()][mp[x[0]]][mp[x.back()]]++, aa[x.size()][mp[x.back()]][mp[x[0]]]++; } for(int i=3; i<=10; i++){ for(int b=0; b<62; b++){ for(int cc=b; cc<62; cc++){ for(int j=0; j<62; j++){ prod[i][b][cc][j] = mul(aa[i][b][j], aa[i][cc][j]); } } } for(int a=0; a<62; a++){ for(int b=a; b<62; b++){ for(int cc=b; cc<62; cc++){ for(int j=0; j<62; j++){ if ((c[i][a][b][cc] += aa[i][a][j] * prod[i][b][cc][j]) >= msq) c[i][a][b][cc] -= msq; } c[i][a][b][cc] %= mod; } } } } int ans=0; for(int i=3; i<=10; i++){ for(int a=0; a<62; a++){ for(int b=a; b<62; b++){ for(int cc=b; cc<62; cc++){ for(int d=cc; d<62; d++){ int val = 0; if(d==a) val = 291154603; else if(d==b) val=166374059; else if(cc==a) val= 166374059; else if(b==a && d==cc) val=748683265; else if(d==cc || b==a) val= 499122177; else if(cc==b) val = 499122177; else val=1; if (val != 1) { if ((ans += val * mul(mul(c[i][a][b][cc], c[i][a][b][d]), mul(c[i][b][cc][d], c[i][a][cc][d]))) >= msq) ans -= msq; } else { if ((ans += mul(c[i][a][b][cc], c[i][a][b][d]) * mul(c[i][b][cc][d], c[i][a][cc][d])) >= msq) ans -= msq; } } ans %= mod; } } } } ans = (ans * 24) % mod; cout<<ans<<'\n'; } signed main() { int t = 1; #ifdef galen_colin_local cin >> t; #endif while (t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...