Submission #946807

#TimeUsernameProblemLanguageResultExecution timeMemory
946807galen_colinCubeword (CEOI19_cubeword)C++17
100 / 100
111 ms28612 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 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; } void sum(int &a){ if(a>=msq) a-=msq; } 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 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++){ c[i][a][b][cc] += aa[i][a][j] * mul(aa[i][b][j], aa[i][cc][j]); sum(c[i][a][b][cc]); } 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 = 1; else if(d==b) val=4; else if(cc==a) val= 4; else if(b==a && d==cc) val=6; else if(d==cc || b==a) val=12; else if(cc==b) val = 12; else val=24; 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])); } ans %= 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...