SHARE
TWEET

Cubeword

Dorijanko Jul 25th, 2019 (edited) 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. #define pb push_back
  3. #pragma GCC optimize("unroll-loops")
  4. #pragma GCC target("avx2")
  5.  
  6. using namespace std;
  7.  
  8. const int CNT=62,SZ=7,MOD=998244353;
  9. int n;
  10. string a;
  11. vector<string> v;
  12. int cnt[SZ+1][CNT][CNT],cnt2[SZ+1][CNT][CNT][CNT],val[250];
  13.  
  14. int main()
  15. {
  16.     ios_base::sync_with_stdio(false);
  17.     cin.tie(0);
  18.     for (int i='a';i<='z';++i) val[i]=i-'a';
  19.     for (int i='A';i<='Z';++i) val[i]=i-'A'+26;
  20.     for (int i='0';i<='9';++i) val[i]=i-'0'+52;
  21.     cin>>n;
  22.     while (n--)
  23.     {
  24.         cin>>a;
  25.         v.pb(a);
  26.         reverse(a.begin(),a.end());
  27.         v.pb(a);
  28.     }
  29.     sort(v.begin(),v.end());
  30.     for (int i=0;i<v.size();++i) if (i==0 || v[i]!=v[i-1])
  31.     {
  32.         a=v[i];
  33.         ++cnt[a.size()-3][val[a[0]]][val[a.back()]];
  34.     }
  35.     for (int s=0;s<=SZ;++s) for (int i=0;i<CNT;++i) for (int j=0;j<CNT;++j) for (int k=0;k<CNT;++k) for (int l=0;l<CNT;++l) cnt2[s][i][j][k]=(cnt2[s][i][j][k]+1ll*cnt[s][i][l]*cnt[s][j][l]*cnt[s][k][l])%MOD;
  36.     int an=0;
  37.     for (int s=0;s<=SZ;++s) for (int i=0;i<CNT;++i) for (int j=0;j<CNT;++j) for (int k=0;k<CNT;++k) for (int l=0;l<CNT;++l) an=(an+1ll*cnt2[s][i][j][k]*cnt2[s][i][j][l]%MOD*cnt2[s][i][k][l]%MOD*cnt2[s][j][k][l])%MOD;
  38.     cout<<an;
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top